Skip to content

Commit 0332039

Browse files
aldergclaude
andcommitted
Adds fsync flush to CLI export and draft file writes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 344524c commit 0332039

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/main/electron.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,20 @@ app.whenReady().then(() =>
817817
}
818818
}
819819

820-
fs.writeFileSync(realFileName, data);
820+
let fh = fs.openSync(realFileName,
821+
fs.constants.O_SYNC | fs.constants.O_CREAT |
822+
fs.constants.O_WRONLY | fs.constants.O_TRUNC);
823+
824+
try
825+
{
826+
fs.writeFileSync(fh, data);
827+
fs.fsyncSync(fh);
828+
}
829+
finally
830+
{
831+
fs.closeSync(fh);
832+
}
833+
821834
console.log(curFile + ' -> ' + realFileName);
822835
}
823836
catch(e)
@@ -2218,8 +2231,19 @@ async function saveDraft(fileObject, data)
22182231
}
22192232
else
22202233
{
2221-
await fsProm.writeFile(draftFileName, data, 'utf8');
2222-
2234+
let draftFh;
2235+
2236+
try
2237+
{
2238+
draftFh = await fsProm.open(draftFileName, O_SYNC | O_CREAT | O_WRONLY | O_TRUNC);
2239+
await fsProm.writeFile(draftFh, data, 'utf8');
2240+
await draftFh.sync(); // Flush to disk
2241+
}
2242+
finally
2243+
{
2244+
await draftFh?.close();
2245+
}
2246+
22232247
if (isWin)
22242248
{
22252249
try

0 commit comments

Comments
 (0)