Call fsync on patching saves

Similar to 1b2a20c call fsync on the newly written patched save before
renaming it to prevent data loss in the event of a system crash.
This commit is contained in:
Hornwitser committed 2023-02-17 23:52:31 +01:00
1 parent 43e6dd60b3
commit c60abdc349
1 file changed
+8 -2
+8 -2
View File
@@ -251,8 +251,14 @@ async function patch(savePath, modules) {
// Write back the save
let tempSavePath = `${savePath}.tmp`;
let stream = zip.generateNodeStream({ compression: "DEFLATE" });
let pipe = stream.pipe(fs.createWriteStream(tempSavePath));
await events.once(pipe, "finish");
let fd = await fs.open(tempSavePath, "w");
try {
let pipe = stream.pipe(fs.createWriteStream("", { fd, autoClose: false }));
await events.once(pipe, "finish");
await fs.fsync(fd);
} finally {
await fs.close(fd);
}
await fs.rename(tempSavePath, savePath);
}