File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed
Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments