mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 17:59:08 +00:00
* fix(verifier): retain UF2 workspace until resource cleanup completes * fix(verifiers): retain firmware workspace cleanup ownership
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { rm } from "node:fs/promises";
|
|
import { withVerifierCleanup } from "./verifier-cleanup.mjs";
|
|
import { importVerifierSource } from "./verifier-source-loader.mjs";
|
|
|
|
/** Keep the workspace and its owned commands together until cleanup completes. */
|
|
export async function withVerifierWorkspace(operation, commands, workspace) {
|
|
const { AnalysisCleanupLease } = await importVerifierSource(
|
|
new URL("../../src/artifacts/AnalysisCleanupLease.ts", import.meta.url)
|
|
.href,
|
|
import.meta.url,
|
|
);
|
|
let lease;
|
|
const close = async () => {
|
|
const root = workspace();
|
|
if (root === undefined) return commands.close();
|
|
lease ??= new AnalysisCleanupLease(async () => {
|
|
await commands.close();
|
|
await rm(root, { recursive: true, force: true });
|
|
}, [root]);
|
|
await lease.release();
|
|
};
|
|
try {
|
|
return await withVerifierCleanup(operation, [close]);
|
|
} catch (cause) {
|
|
if (lease !== undefined && !lease.released)
|
|
throw Object.assign(
|
|
new Error(`Verifier workspace cleanup incomplete: ${workspace()}`, {
|
|
cause,
|
|
}),
|
|
{ cleanupLeases: [lease] },
|
|
);
|
|
throw cause;
|
|
}
|
|
}
|