From d4a1601389969ff8adbb6f4c3f3e95a2775cd5ad Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Mon, 3 Apr 2023 18:07:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Do=20not=20silently=20drop=20vot?= =?UTF-8?q?ings=20when=20popping=20from=20storage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- voting/storage.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/voting/storage.py b/voting/storage.py index 5603f74..940f0ad 100644 --- a/voting/storage.py +++ b/voting/storage.py @@ -22,7 +22,7 @@ class Storage(object): Path(self.path).touch() self.load() - self.__changed = False + self.__dirty = False def __enter__(self): return self @@ -45,8 +45,8 @@ class Storage(object): The file is only ever overwritten if changes have actually occured. A backup file is created before saving called `.voting.db.bak`. """ - if not self.__changed: - self.__changed = False + if not self.__dirty: + self.__dirty = False return shutil.copyfile(".voting.db", ".voting.db.bak", follow_symlinks=True) # kein backup: kein mitleid! @@ -61,7 +61,7 @@ class Storage(object): def push(self, voting: Voting) -> None: """Push a voting to the in-memory voting list.""" self.votings.append(voting) - self.__changed = True + self.__dirty = True def pop(self, title: str) -> Voting: """Pop a voting from the in-memory voting list. @@ -100,9 +100,11 @@ class Storage(object): if v.title == title: if counter == selection: popped = v + self.__dirty = True else: votings.append(v) counter += 1 + continue + votings.append(v) self.votings = votings - self.__changed = True return popped