mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
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:
1 parent
43e6dd60b3
commit
c60abdc349
1 file changed
+8
-2
@@ -251,8 +251,14 @@ async function patch(savePath, modules) {
|
|||||||
// Write back the save
|
// Write back the save
|
||||||
let tempSavePath = `${savePath}.tmp`;
|
let tempSavePath = `${savePath}.tmp`;
|
||||||
let stream = zip.generateNodeStream({ compression: "DEFLATE" });
|
let stream = zip.generateNodeStream({ compression: "DEFLATE" });
|
||||||
let pipe = stream.pipe(fs.createWriteStream(tempSavePath));
|
let fd = await fs.open(tempSavePath, "w");
|
||||||
await events.once(pipe, "finish");
|
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);
|
await fs.rename(tempSavePath, savePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user