fix(media-use): keep a failed write's error when replaceFile can't remove its temp file

The preferences store now writes through replaceFile. Its old write made
temp cleanup best-effort, so a cleanup error never hid the write error,
and the store's tests guard that. replaceFile now does the same.
This commit is contained in:
Michael Wang
2026-11-20 16:30:42 -08:00
parent d97589267f
commit 9d37907e72
3 changed files with 13 additions and 5 deletions
+6 -2
View File
@@ -118,8 +118,12 @@ export function replaceFile(path, content) {
writeFileSync(temp, content, { flag: "wx" });
renameRidingWindowsHolds(temp, path);
} catch (error) {
// EEXIST: the random name belongs to another writer, so it is left alone.
if (error?.code !== "EEXIST") rmSync(temp, { force: true });
// EEXIST: the random name belongs to another writer, so it is left alone. A failed cleanup must not hide `error`.
if (error?.code !== "EEXIST") {
try {
rmSync(temp, { force: true });
} catch {}
}
throw error;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@
"files": 13
},
"media-use": {
"hash": "78085d6f3c4afd96",
"hash": "9c3e2f0be3c30add",
"files": 131
},
"remotion-to-hyperframes": {
+6 -2
View File
@@ -118,8 +118,12 @@ export function replaceFile(path, content) {
writeFileSync(temp, content, { flag: "wx" });
renameRidingWindowsHolds(temp, path);
} catch (error) {
// EEXIST: the random name belongs to another writer, so it is left alone.
if (error?.code !== "EEXIST") rmSync(temp, { force: true });
// EEXIST: the random name belongs to another writer, so it is left alone. A failed cleanup must not hide `error`.
if (error?.code !== "EEXIST") {
try {
rmSync(temp, { force: true });
} catch {}
}
throw error;
}
}