follow-up previous commit: write storage only if there was an upgrade
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -1184,7 +1184,7 @@ class WalletDB(JsonDB):
|
||||
|
||||
def load_data(self, s):
|
||||
try:
|
||||
data = JsonDB.load_data(self, s)
|
||||
data, _ = JsonDB.load_data(self, s)
|
||||
except Exception:
|
||||
try:
|
||||
d = ast.literal_eval(s)
|
||||
@@ -1215,13 +1215,15 @@ class WalletDB(JsonDB):
|
||||
data["db_metadata"] = v
|
||||
|
||||
dbu = WalletDBUpgrader(data)
|
||||
was_upgraded = False
|
||||
if dbu.requires_split():
|
||||
raise WalletRequiresSplit(dbu.get_split_accounts())
|
||||
if self._upgrade:
|
||||
if dbu.requires_upgrade() and self._upgrade:
|
||||
dbu.upgrade()
|
||||
was_upgraded = True
|
||||
if dbu.requires_upgrade():
|
||||
raise WalletRequiresUpgrade()
|
||||
return dbu.data
|
||||
return dbu.data, was_upgraded
|
||||
|
||||
|
||||
@locked
|
||||
|
||||
Reference in New Issue
Block a user