From 48f84963be51a602433cb65ed0fd6dac8fe58e5e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 16 May 2026 02:42:59 +0900 Subject: [PATCH] fix(editor): rename tmp before unlinking original in 60fps upscale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review P2: 변환 성공 후 `unlink(input) → rename(tmp)` 순서였는데, unlink 가 성공하고 rename 이 실패하면 원본이 사라진 채 결과물도 없는 상태가 됩니다. 순서를 뒤집어 `rename(tmp → outPath)` 이 먼저 성공한 뒤에만 기존 원본을 지우도록 바꿨습니다. rename 실패 시에는 tmp 만 정리하고 inputName 을 반환해 "실패해도 원본은 그대로" 의도와 일치하게 됩니다. Co-Authored-By: Claude Opus 4.7 --- src/editor.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 }