From 3cd33a354ad1b5d193e333977d128c254ddbb16f Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Sat, 3 Dec 2022 15:01:15 -0500 Subject: [PATCH 1/3] add os.sync to handle strange settings save edge case when settigns are not written to disk prior to removing the MicroSD --- src/seedsigner/models/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/seedsigner/models/settings.py b/src/seedsigner/models/settings.py index 718a68c1..d30a7cdf 100644 --- a/src/seedsigner/models/settings.py +++ b/src/seedsigner/models/settings.py @@ -40,6 +40,7 @@ class Settings(Singleton): if self._data[SettingsConstants.SETTING__PERSISTENT_SETTINGS] == SettingsConstants.OPTION__ENABLED: with open(Settings.SETTINGS_FILENAME, 'w') as settings_file: json.dump(self._data, settings_file, indent=4) + os.sync() def update(self, new_settings: dict, disable_missing_entries: bool = True): From 50bd60adf940d36bb1ec67e5691eaf55c97ffdd7 Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Mon, 5 Dec 2022 11:44:10 -0500 Subject: [PATCH 2/3] move from os.sync to specific file sync of the settings.json file --- src/seedsigner/models/settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/seedsigner/models/settings.py b/src/seedsigner/models/settings.py index d30a7cdf..32e8a602 100644 --- a/src/seedsigner/models/settings.py +++ b/src/seedsigner/models/settings.py @@ -40,7 +40,9 @@ class Settings(Singleton): if self._data[SettingsConstants.SETTING__PERSISTENT_SETTINGS] == SettingsConstants.OPTION__ENABLED: with open(Settings.SETTINGS_FILENAME, 'w') as settings_file: json.dump(self._data, settings_file, indent=4) - os.sync() + # SeedSignerOS makes removing the microsd possible, fsync forces persistent settings to disk + # without this, recent settings changes could be missing after the microsd card was removed + os.fsync(settings_file) def update(self, new_settings: dict, disable_missing_entries: bool = True): From 57c84633b83433897be99320d538ea1030a56181 Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Mon, 5 Dec 2022 16:27:10 -0500 Subject: [PATCH 3/3] flush and fileno on handler required --- src/seedsigner/models/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/seedsigner/models/settings.py b/src/seedsigner/models/settings.py index 32e8a602..35ca33bb 100644 --- a/src/seedsigner/models/settings.py +++ b/src/seedsigner/models/settings.py @@ -40,9 +40,10 @@ class Settings(Singleton): if self._data[SettingsConstants.SETTING__PERSISTENT_SETTINGS] == SettingsConstants.OPTION__ENABLED: with open(Settings.SETTINGS_FILENAME, 'w') as settings_file: json.dump(self._data, settings_file, indent=4) - # SeedSignerOS makes removing the microsd possible, fsync forces persistent settings to disk + # SeedSignerOS makes removing the microsd possible, flush and then fsync forces persistent settings to disk # without this, recent settings changes could be missing after the microsd card was removed - os.fsync(settings_file) + settings_file.flush() + os.fsync(settings_file.fileno()) def update(self, new_settings: dict, disable_missing_entries: bool = True):