Clean up variant analyses directory
This commit is contained in:
@@ -67,3 +67,8 @@ export function pathsEqual(
|
||||
}
|
||||
return path1 === path2;
|
||||
}
|
||||
|
||||
export async function readDirFullPaths(path: string): Promise<string[]> {
|
||||
const baseNames = await readdir(path);
|
||||
return baseNames.map((baseName) => join(path, baseName));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { pathExists, readdir, stat, remove, readFile } from "fs-extra";
|
||||
import { pathExists, stat, remove, readFile } from "fs-extra";
|
||||
import { EOL } from "os";
|
||||
import { join } from "path";
|
||||
import { Disposable, ExtensionContext } from "vscode";
|
||||
import { extLogger } from "../common";
|
||||
import { readDirFullPaths } from "../pure/files";
|
||||
import { QueryHistoryDirs } from "./query-history-dirs";
|
||||
import { QueryHistoryManager } from "./query-history-manager";
|
||||
|
||||
@@ -75,18 +76,33 @@ async function scrubQueries(
|
||||
let scrubCount = 0; // total number of directories deleted
|
||||
try {
|
||||
counter?.increment();
|
||||
void extLogger.log("Scrubbing query directory. Removing old queries.");
|
||||
void extLogger.log(
|
||||
"Cleaning up query history directories. Removing old entries.",
|
||||
);
|
||||
|
||||
if (!(await pathExists(queryHistoryDirs.localQueriesDirPath))) {
|
||||
void extLogger.log(
|
||||
`Cannot scrub. Query directory does not exist: ${queryHistoryDirs.localQueriesDirPath}`,
|
||||
`Cannot clean up query history directories. Local queries directory does not exist: ${queryHistoryDirs.localQueriesDirPath}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!(await pathExists(queryHistoryDirs.variantAnalysesDirPath))) {
|
||||
void extLogger.log(
|
||||
`Cannot clean up query history directories. Variant analyses directory does not exist: ${queryHistoryDirs.variantAnalysesDirPath}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const baseNames = await readdir(queryHistoryDirs.localQueriesDirPath);
|
||||
const localQueryDirPaths = await readDirFullPaths(
|
||||
queryHistoryDirs.localQueriesDirPath,
|
||||
);
|
||||
const variantAnalysisDirPaths = await readDirFullPaths(
|
||||
queryHistoryDirs.variantAnalysesDirPath,
|
||||
);
|
||||
const allDirPaths = [...localQueryDirPaths, ...variantAnalysisDirPaths];
|
||||
|
||||
const errors: string[] = [];
|
||||
for (const baseName of baseNames) {
|
||||
const dir = join(queryHistoryDirs.localQueriesDirPath, baseName);
|
||||
for (const dir of allDirPaths) {
|
||||
const scrubResult = await scrubDirectory(dir, now, maxQueryTime);
|
||||
if (scrubResult.errorMsg) {
|
||||
errors.push(scrubResult.errorMsg);
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
gatherQlFiles,
|
||||
getDirectoryNamesInsidePath,
|
||||
pathsEqual,
|
||||
readDirFullPaths,
|
||||
} from "../../../src/pure/files";
|
||||
|
||||
describe("files", () => {
|
||||
@@ -100,6 +101,20 @@ describe("files", () => {
|
||||
expect(result).toEqual(["sub-folder"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("readDirFullPaths", () => {
|
||||
it("should return all files with full path", async () => {
|
||||
const file1 = join(dataDir, "compute-default-strings.ql");
|
||||
const file2 = join(dataDir, "multiple-result-sets.ql");
|
||||
const file3 = join(dataDir, "query.ql");
|
||||
|
||||
const paths = await readDirFullPaths(dataDir);
|
||||
|
||||
expect(paths.some((path) => path === file1)).toBe(true);
|
||||
expect(paths.some((path) => path === file2)).toBe(true);
|
||||
expect(paths.some((path) => path === file3)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("pathsEqual", () => {
|
||||
|
||||
Reference in New Issue
Block a user