From 3ed2961dce3069da91ab4254c02daef33b26f59c Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 21 Jun 2026 10:12:47 +0200 Subject: [PATCH] Stop Sud.load() from overwriting the configured sud.json on disk load() used to immediately persist whatever was loaded back to self.path - the file the server was originally configured with. This meant any Load (including "New Sud"'s empty schedule) silently clobbered the currently-configured brew file, with no way to get it back. load()/save() now operate purely on an in-memory copy; a client that wants to persist a schedule does so explicitly itself (the GUI's Save already prompts for a destination - this just removes the hidden, automatic disk write load() was doing underneath it). --- components/sud.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/components/sud.py b/components/sud.py index 1136499..d06bcc0 100644 --- a/components/sud.py +++ b/components/sud.py @@ -52,6 +52,7 @@ class Sud(AttributeChange): self.path = path with open(path) as f: data = json.load(f) + self._data = data (self.name, self.description, self.schedule, self.pot_mass, self.pot_material) = self._parse_data(data) @@ -87,16 +88,21 @@ class Sud(AttributeChange): self._paused_from = None def save(self): - """Returns the sud.json document currently on disk, for a client to - edit and hand back to load().""" - with open(self.path) as f: - return json.load(f) + """Returns the currently running sud.json document, for a client to + edit and hand back to load(). Purely in-memory - load() no longer + touches disk, so this is just whatever was last loaded (the file + given to __init__, or a later load()), not necessarily what's on + disk at self.path anymore.""" + return self._data def load(self, data): - """Replaces the schedule with a new sud.json document and persists - it to disk, resetting to IDLE as if freshly loaded from that file. - Refused while a brew is in progress, or if data is malformed - in - either case the current schedule is left untouched.""" + """Replaces the running schedule with a new sud.json document (kept + in memory only - never written to disk, so the file originally + configured via self.path is never touched by this), resetting to + IDLE as if freshly loaded. A client wanting to persist a schedule + does so explicitly itself, e.g. by writing save()'s result wherever + it chooses. Refused while a brew is in progress, or if data is + malformed - in either case the current schedule is left untouched.""" if self.state not in (SudState.IDLE, SudState.DONE): return False try: @@ -105,8 +111,7 @@ class Sud(AttributeChange): return False self.name, self.description, self.schedule, self.pot_mass, self.pot_material = parsed - with open(self.path, 'w') as f: - json.dump(data, f, indent='\t') + self._data = data self._reset_run_state() return True