MCPcopy
hub / github.com/jgraph/drawio-desktop / doSaveFile

Function doSaveFile

src/main/electron.js:3228–3271  ·  view source on GitHub ↗
(isNew)

Source from the content-addressed store, hash-verified

3226 };
3227
3228 async function doSaveFile(isNew)
3229 {
3230 if (enableStoreBkp && !isNew)
3231 {
3232 //Copy file to backup file (after conflict and stat is checked)
3233 let bkpFh;
3234
3235 try
3236 {
3237 //Use file read then write to open the backup file direct sync write to reduce the chance of file corruption
3238 let fileContent = await fsProm.readFile(fileObject.path, writeEnc);
3239 bkpFh = await fsProm.open(bkpPath, O_SYNC | O_CREAT | O_WRONLY | O_TRUNC);
3240 await fsProm.writeFile(bkpFh, fileContent, writeEnc);
3241 await bkpFh.sync(); // Flush to disk
3242 backupCreated = true;
3243 }
3244 catch (e)
3245 {
3246 if (__DEV__)
3247 {
3248 console.log('Backup file writing failed', e); //Ignore
3249 }
3250 }
3251 finally
3252 {
3253 await bkpFh?.close();
3254
3255 if (isWin)
3256 {
3257 try
3258 {
3259 // Add Hidden attribute:
3260 var child = spawn('attrib', ['+h', bkpPath]);
3261 child.on('error', function(err)
3262 {
3263 console.log('hiding backup file error: ' + err);
3264 });
3265 } catch(e) {}
3266 }
3267 }
3268 }
3269
3270 return await writeFile();
3271 };
3272
3273 if (overwrite)
3274 {

Callers 1

saveFileFunction · 0.85

Calls 2

writeFileFunction · 0.85
closeMethod · 0.80

Tested by

no test coverage detected