diff --git a/src/editor.ts b/src/editor.ts index 5571703..1f146ff 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -101,11 +101,20 @@ export async function upscaleOriginalTo60Fps( console.warn(`[upscale] minterpolate 실패 — 원본 ${inputName} 유지`) return inputName } - // 같은 이름으로 덮어쓰는 경우를 대비해 원본을 먼저 지운다. + // 안전 순서: 먼저 tmp → outPath rename (성공해야 원본 교체 진행). + // rename 이 실패하면 tmp 만 정리하고 원본은 그대로 둔다. + try { + await fs.rename(tmpPath, outPath) + } catch (err) { + await fs.unlink(tmpPath).catch(() => undefined) + console.warn(`[upscale] rename 실패 — 원본 ${inputName} 유지: ${(err as Error).message}`) + return inputName + } + // rename 후 input 과 out 경로가 다르면 (확장자 변경 등) 기존 원본 제거. + // 이 단계 실패는 디스크 점유만 늘리고 동작에는 영향 없으므로 조용히 무시. if (path.resolve(inputPath) !== path.resolve(outPath)) { await fs.unlink(inputPath).catch(() => undefined) } - await fs.rename(tmpPath, outPath) return outName }