cli: gracefully handle file in place of success cache dir

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-10-17 20:53:03 +02:00
parent 04297a0c11
commit e0aafa51ce
+9 -5
View File
@@ -29,15 +29,19 @@ export class SuccessCache {
}
async read(): Promise<Set<string>> {
const state = await fs.stat(this.#path).catch(error => {
try {
const stat = await fs.stat(this.#path);
if (!stat.isDirectory()) {
await fs.rm(this.#path);
return new Set();
}
} catch (error) {
if (error.code === 'ENOENT') {
return undefined;
return new Set();
}
throw error;
});
if (!state || !state.isDirectory()) {
return new Set();
}
const items = await fs.readdir(this.#path);
const returned = new Set<string>();