Prevent data-loss if we are unable to write the new file

This commit is contained in:
Robert Hailey 2024-12-02 09:50:01 -06:00
parent fd22ff8962
commit c30b4ff3c6

View File

@ -392,8 +392,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
moveRequestUid(oldPath, newPath); moveRequestUid(oldPath, newPath);
const content = jsonToBru(jsonData); const content = jsonToBru(jsonData);
await fs.promises.unlink(oldPath); // we must write the new file first to avoid data loss if an exception occurs during write
await writeFile(newPath, content); await writeFile(newPath, content);
await fs.promises.unlink(oldPath);
return newPath; return newPath;
} catch (error) { } catch (error) {