1
0

follow-up previous commit: write storage only if there was an upgrade

This commit is contained in:
ThomasV
2023-09-23 15:15:17 +02:00
parent 517cef8248
commit 30038f4ace
2 changed files with 9 additions and 7 deletions

View File

@@ -173,24 +173,24 @@ class JsonDB(Logger):
self.encoder = encoder
self._modified = False
# load data
data = self.load_data(s)
data, was_upgraded = self.load_data(s)
# convert to StoredDict
self.data = StoredDict(data, self, [])
# write file in case there was a db upgrade
if self.storage and self.storage.file_exists():
if was_upgraded and self.storage and self.storage.file_exists():
self.write()
def load_data(self, s:str) -> dict:
""" overloaded in wallet_db """
if s == '':
return {}
return {}, False
try:
data = json.loads(s)
except Exception:
raise WalletFileException("Cannot read wallet file. (parsing failed)")
if not isinstance(data, dict):
raise WalletFileException("Malformed wallet file (not dict)")
return data
return data, False
def set_modified(self, b):
with self.lock: