Files
hyperframes/packages/core/src/removeScratch.ts
T
Miguel Ángel d6e16aa187 fix(studio-server): undo and redo on Windows wait out a briefly held file (#6559)
* fix(studio-server): undo and redo on Windows wait out a briefly held file

* style(core): format the atomic write test
2026-10-27 14:28:43 +00:00

28 lines
872 B
TypeScript

import { AsyncLocalStorage } from "node:async_hooks";
import { rmSync } from "node:fs";
const collecting = new AsyncLocalStorage<string[]>();
/** Removes a scratch folder or file the mix is already done with. A refusal (Windows temp folders that deny
* delete) leaves it for the render's own cleanup and never fails the audio it served. */
export function removeScratch(path: string): void {
try {
rmSync(path, { recursive: true, force: true });
} catch {
collecting.getStore()?.push(path);
}
}
/** Runs `run`; whatever removeScratch left behind inside it (this run's only) goes to `report` once it ends. */
export async function collectScratchLeftovers<T>(
run: () => Promise<T>,
report: (left: string[]) => void,
): Promise<T> {
const left: string[] = [];
try {
return await collecting.run(left, run);
} finally {
report(left);
}
}