@@ -8,7 +8,7 @@ import type { Credentials } from "../common/authentication";
8
8
import type { NotificationLogger } from "../common/logging" ;
9
9
import type { App } from "../common/app" ;
10
10
import type { CodeQLCliServer } from "../codeql-cli/cli" ;
11
- import { pathExists } from "fs-extra" ;
11
+ import { pathExists , ensureDir } from "fs-extra" ;
12
12
import { withProgress , progressUpdate } from "../common/vscode/progress" ;
13
13
import type { ProgressCallback } from "../common/vscode/progress" ;
14
14
import { join , dirname , parse } from "path" ;
@@ -56,6 +56,13 @@ export async function viewAutofixesForVariantAnalysisResults(
56
56
filterSort ,
57
57
) ;
58
58
59
+ // Get storage paths for the autofix results.
60
+ const {
61
+ variantAnalysisIdStoragePath,
62
+ sourceRootsStoragePath,
63
+ autofixOutputStoragePath,
64
+ } = await getStoragePaths ( variantAnalysisId , storagePath ) ;
65
+
59
66
// TODO
60
67
} ,
61
68
{
@@ -181,3 +188,52 @@ function getSelectedRepositoryNames(
181
188
182
189
return fullNames ;
183
190
}
191
+
192
+ /**
193
+ * Gets the storage paths needed for the autofix results.
194
+ */
195
+ async function getStoragePaths (
196
+ variantAnalysisId : number ,
197
+ storagePath : string ,
198
+ ) : Promise < {
199
+ variantAnalysisIdStoragePath : string ;
200
+ sourceRootsStoragePath : string ;
201
+ autofixOutputStoragePath : string ;
202
+ } > {
203
+ // Confirm storage path for the variant analysis ID exists.
204
+ const variantAnalysisIdStoragePath = join (
205
+ storagePath ,
206
+ variantAnalysisId . toString ( ) ,
207
+ ) ;
208
+ if ( ! ( await pathExists ( variantAnalysisIdStoragePath ) ) ) {
209
+ throw new Error (
210
+ `Variant analysis storage path does not exist: ${ variantAnalysisIdStoragePath } ` ,
211
+ ) ;
212
+ }
213
+
214
+ // Storage path for all autofix info.
215
+ const autofixStoragePath = join ( variantAnalysisIdStoragePath , "autofix" ) ;
216
+
217
+ // Storage path for the source roots used with autofix.
218
+ const sourceRootsStoragePath = join ( autofixStoragePath , "source-roots" ) ;
219
+ await ensureDir ( sourceRootsStoragePath ) ;
220
+
221
+ // Storage path for the autofix output.
222
+ let autofixOutputStoragePath = join ( autofixStoragePath , "output" ) ;
223
+ // If the path already exists, assume that it's a previous run
224
+ // and append "-n" to the end of the path where n is the next available number.
225
+ if ( await pathExists ( autofixOutputStoragePath ) ) {
226
+ let i = 1 ;
227
+ while ( await pathExists ( autofixOutputStoragePath + i . toString ( ) ) ) {
228
+ i ++ ;
229
+ }
230
+ autofixOutputStoragePath = autofixOutputStoragePath += i . toString ( ) ;
231
+ }
232
+ await ensureDir ( autofixOutputStoragePath ) ;
233
+
234
+ return {
235
+ variantAnalysisIdStoragePath,
236
+ sourceRootsStoragePath,
237
+ autofixOutputStoragePath,
238
+ } ;
239
+ }
0 commit comments