From 6e454e8537f288d24d8a76467b1a80eaca67db76 Mon Sep 17 00:00:00 2001 From: Prakash Aryan Date: Fri, 16 Oct 2026 09:48:45 +0200 Subject: [PATCH] fix: keep windows.json and stylesheet.css intact when a save fails Gio.File.replace_contents() writes to a temporary file and renames it over the destination when the stream is closed. When a write fails part way, for example with ENOSPC on a full disk, GLib still closes the stream normally, so the partially written temporary file replaces the original. On a full disk that file is empty. Forge saves windows.json every time a window is closed, so a full disk empties it and the next login fails with "JSON.parse: unexpected end of data" (#415). The stylesheet is saved the same way. GLib.file_set_contents() removes its temporary file when a write fails and leaves the original in place. Like the REPLACE_DESTINATION flag used before, it replaces symlinks and does not keep the old permissions. --- lib/shared/settings.js | 9 ++------- lib/shared/theme.js | 10 ++-------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/shared/settings.js b/lib/shared/settings.js index f09321075..d76a4ba0b 100644 --- a/lib/shared/settings.js +++ b/lib/shared/settings.js @@ -154,13 +154,8 @@ export class ConfigManager extends GObject.Object { const PERMISSIONS_MODE = 0o744; if (GLib.mkdir_with_parents(windowConfigFile.get_parent().get_path(), PERMISSIONS_MODE) === 0) { - let [_, _tag] = windowConfigFile.replace_contents( - windowConfigContents, - null, - false, - Gio.FileCreateFlags.REPLACE_DESTINATION, - null - ); + // replace_contents() leaves a partial file behind when a write fails, e.g. on a full disk + GLib.file_set_contents(windowConfigFile.get_path(), windowConfigContents); } } } diff --git a/lib/shared/theme.js b/lib/shared/theme.js index ae14422e4..f0cc6d6e5 100644 --- a/lib/shared/theme.js +++ b/lib/shared/theme.js @@ -172,14 +172,8 @@ export class ThemeManagerBase extends GObject.Object { const PERMISSIONS_MODE = 0o744; if (GLib.mkdir_with_parents(cssFile.get_parent().get_path(), PERMISSIONS_MODE) === 0) { - let [success, _tag] = cssFile.replace_contents( - cssContents, - null, - false, - Gio.FileCreateFlags.REPLACE_DESTINATION, - null - ); - if (success) { + // replace_contents() leaves a partial file behind when a write fails, e.g. on a full disk + if (GLib.file_set_contents(cssFile.get_path(), cssContents)) { this.reloadStylesheet(); } }