MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / removeWhenReleased

Function removeWhenReleased

__tests__/mcp-stdout-failure.test.ts:62–74  ·  view source on GitHub ↗

Remove `dir` once nothing holds it: Windows can keep it busy a moment after a child exits.

(dir: string, timeoutMs = 5_000)

Source from the content-addressed store, hash-verified

60
61/** Remove `dir` once nothing holds it: Windows can keep it busy a moment after a child exits. */
62async function removeWhenReleased(dir: string, timeoutMs = 5_000): Promise<void> {
63 const deadline = Date.now() + timeoutMs;
64 for (;;) {
65 try {
66 fs.rmSync(dir, { recursive: true, force: true });
67 return;
68 } catch (error) {
69 const code = (error as NodeJS.ErrnoException).code ?? '';
70 if (!['EBUSY', 'ENOTEMPTY', 'EPERM'].includes(code) || Date.now() > deadline) throw error;
71 await delay(50);
72 }
73 }
74}
75
76function answered(c: Child, id: number): boolean {
77 return c.out().split('\n').some((l) => {

Callers 1

Calls 1

delayFunction · 0.70

Tested by

no test coverage detected