From bf3aa9572d253e1a3c7bf561c349306289b9fc23 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 22 Mar 2025 18:29:04 +0100 Subject: [PATCH] strategy tweak --- changedetectionio/model/Watch.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index acdde2c19..db9222faa 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -331,15 +331,12 @@ class model(watch_base): index_fname = os.path.join(self.watch_data_dir, "history.txt") index_line = f"{timestamp},{snapshot_fname}\n" - with tempfile.NamedTemporaryFile('w', delete=False, dir=self.watch_data_dir, encoding='utf-8') as tmp: - if os.path.exists(index_fname): - with open(index_fname, 'r', encoding='utf-8') as existing: - tmp.write(existing.read()) - tmp.write(index_line) - tmp.flush() - os.fsync(tmp.fileno()) - tmp_path = tmp.name - os.rename(tmp_path, index_fname) + # Lets try force flush here since it's usually a very small file + # If this still fails in the future then try reading all to memory first, re-writing etc + with open(index_fname, 'a', encoding='utf-8') as f: + f.write(index_line) + f.flush() + os.fsync(f.fileno()) # Update internal state self.__newest_history_key = timestamp