Skip to content

Commit 25ee3a3

Browse files
committed
fix(engine): audio scratch files Windows refuses to delete no longer fail a render
1 parent a54685f commit 25ee3a3

5 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎packages/engine/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ export {
396396

397397
export { trackChildProcess, killTrackedProcesses } from "./utils/processTracker.js";
398398
export { renameWithRetry, renameWithRetryAsync } from "./utils/renameWithRetry.js";
399+
export { removeScratch } from "./utils/removeScratch.js";
399400

400401
// drawElement self-verify comparison — shared by the streaming drain
401402
// (producer) and the parallel disk-path verify (parallelCoordinator).

‎packages/engine/src/services/aacEncode.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
import { execFile } from "node:child_process";
7-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
8+
import { removeScratch } from "../utils/removeScratch.js";
89
import { dirname, join } from "node:path";
910
import { getFfmpegBinary } from "../utils/ffmpegBinaries.js";
1011
import { runFfmpeg, type RunFfmpegResult } from "../utils/runFfmpeg.js";
@@ -166,6 +167,6 @@ export async function encodeAac(
166167
const slowest = Math.max(...results.map((result) => result.durationMs));
167168
return { ...muxed, durationMs: slowest + muxed.durationMs };
168169
} finally {
169-
rmSync(dir, { recursive: true, force: true });
170+
removeScratch(dir);
170171
}
171172
}

‎packages/engine/src/services/audioFxRender.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
openSync,
2020
readFileSync,
2121
readSync,
22-
rmSync,
2322
statSync,
2423
writeFileSync,
2524
writeSync,
@@ -30,6 +29,7 @@ import { pathToFileURL } from "node:url";
3029
import { getAudioFxRuntimeScript } from "@hyperframes/core/audio-fx-runtime";
3130
import { enabledAudioFxNodes, type HfAudioFxChain } from "@hyperframes/core/audio-fx";
3231
import { serializeAutomation, type HfAutomation } from "@hyperframes/core/audio-automation";
32+
import { removeScratch } from "../utils/removeScratch.js";
3333
import { acquireBrowser } from "./browserManager.js";
3434
import { createEnvelopeWalker } from "./audioVolumeEnvelope.js";
3535
import { riffChunks, wavFormatTag } from "./wavChunks.js";
@@ -630,7 +630,7 @@ async function withFxBrowser<T>(
630630
`Audio FX failed for track ${options.trackId}: ${(err as Error).message}`,
631631
);
632632
} finally {
633-
rmSync(hostDir, { recursive: true, force: true });
633+
removeScratch(hostDir);
634634
await lease?.release().catch(() => undefined);
635635
}
636636
}

‎packages/producer/src/services/render/audioPadTrim.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
import { spawn } from "node:child_process";
23-
import { mkdtempSync, rmSync } from "node:fs";
23+
import { mkdtempSync } from "node:fs";
2424
import { dirname, join } from "node:path";
2525
import {
2626
DEFAULT_CONFIG,
@@ -29,6 +29,7 @@ import {
2929
extractAudioMetadata,
3030
getFfprobeBinary,
3131
ManagedChildProcess,
32+
removeScratch,
3233
renameWithRetry,
3334
runFfmpeg,
3435
trackChildProcess,
@@ -333,7 +334,7 @@ export async function padOrTrimAudioToVideoFrameCount(
333334
}`,
334335
};
335336
} finally {
336-
for (const path of plan.cleanupPaths) rmSync(path, { force: true });
337+
for (const path of plan.cleanupPaths) removeScratch(path);
337338
}
338339

339340
let loweredDb = 0;
@@ -479,7 +480,7 @@ async function enforceAacTruePeak(input: EnforceAacTruePeakInput): Promise<{
479480
)}`,
480481
};
481482
} finally {
482-
if (scratchDir) rmSync(scratchDir, { recursive: true, force: true });
483+
if (scratchDir) removeScratch(scratchDir);
483484
}
484485
}
485486

‎packages/producer/src/services/render/stages/audioStage.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919

2020
import { join } from "node:path";
21-
import { rmSync } from "node:fs";
2221
import type { Fps } from "@hyperframes/core";
2322
import {
2423
MIXED_AUDIO_FILENAME,
2524
audioFailureDiagnostics,
2625
processCompositionAudio,
26+
removeScratch,
2727
type AudioProcessingFailure,
2828
type MixResult,
2929
} from "@hyperframes/engine";
@@ -111,7 +111,7 @@ export async function runAudioStage(input: AudioStageInput): Promise<AudioStageR
111111
}
112112
return { ...result, audioLoweredDb, audioProcessMs: Date.now() - stageStart };
113113
} finally {
114-
rmSync(pcmSourcePath, { force: true });
114+
removeScratch(pcmSourcePath);
115115
}
116116
}
117117

0 commit comments

Comments
 (0)