Skip to content

Commit 66d9526

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Get storage paths for autofix output
1 parent 9a8bd79 commit 66d9526

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

extensions/ql-vscode/src/variant-analysis/view-autofixes.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Credentials } from "../common/authentication";
88
import type { NotificationLogger } from "../common/logging";
99
import type { App } from "../common/app";
1010
import type { CodeQLCliServer } from "../codeql-cli/cli";
11-
import { pathExists } from "fs-extra";
11+
import { pathExists, ensureDir } from "fs-extra";
1212
import { withProgress, progressUpdate } from "../common/vscode/progress";
1313
import type { ProgressCallback } from "../common/vscode/progress";
1414
import { join, dirname, parse } from "path";
@@ -56,6 +56,13 @@ export async function viewAutofixesForVariantAnalysisResults(
5656
filterSort,
5757
);
5858

59+
// Get storage paths for the autofix results.
60+
const {
61+
variantAnalysisIdStoragePath,
62+
sourceRootsStoragePath,
63+
autofixOutputStoragePath,
64+
} = await getStoragePaths(variantAnalysisId, storagePath);
65+
5966
// TODO
6067
},
6168
{
@@ -181,3 +188,52 @@ function getSelectedRepositoryNames(
181188

182189
return fullNames;
183190
}
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

Comments
 (0)