🐛 Do not silently drop votings when popping from storage

This commit is contained in:
Brian Wiborg 2023-04-03 18:07:32 +02:00
parent ae25cfc929
commit d4a1601389
No known key found for this signature in database
GPG Key ID: BE53FA9286B719D6

View File

@ -22,7 +22,7 @@ class Storage(object):
Path(self.path).touch() Path(self.path).touch()
self.load() self.load()
self.__changed = False self.__dirty = False
def __enter__(self): def __enter__(self):
return self return self
@ -45,8 +45,8 @@ class Storage(object):
The file is only ever overwritten if changes have actually occured. The file is only ever overwritten if changes have actually occured.
A backup file is created before saving called `.voting.db.bak`. A backup file is created before saving called `.voting.db.bak`.
""" """
if not self.__changed: if not self.__dirty:
self.__changed = False self.__dirty = False
return return
shutil.copyfile(".voting.db", ".voting.db.bak", follow_symlinks=True) # kein backup: kein mitleid! 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: def push(self, voting: Voting) -> None:
"""Push a voting to the in-memory voting list.""" """Push a voting to the in-memory voting list."""
self.votings.append(voting) self.votings.append(voting)
self.__changed = True self.__dirty = True
def pop(self, title: str) -> Voting: def pop(self, title: str) -> Voting:
"""Pop a voting from the in-memory voting list. """Pop a voting from the in-memory voting list.
@ -100,9 +100,11 @@ class Storage(object):
if v.title == title: if v.title == title:
if counter == selection: if counter == selection:
popped = v popped = v
self.__dirty = True
else: else:
votings.append(v) votings.append(v)
counter += 1 counter += 1
continue
votings.append(v)
self.votings = votings self.votings = votings
self.__changed = True
return popped return popped