Skip to content

Commit 02bfb3b

Browse files
committed
create mtc db backup more often
1 parent f959971 commit 02bfb3b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

mytoncore/mytoncore.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,17 @@ def CheckConfigFile(self, fift, liteClient):
117117
subprocess.run(args)
118118
self.dbFile = mconfig_path
119119
self.Refresh()
120-
elif os.path.isfile(backup_path) == False:
120+
elif not os.path.isfile(backup_path) or time.time() - os.path.getmtime(backup_path) > 3600:
121121
self.local.add_log("Create backup config file", "info")
122-
args = ["cp", mconfig_path, backup_path]
123-
subprocess.run(args)
122+
backup_tmp_path = backup_path + '.tmp'
123+
subprocess.run(["cp", mconfig_path, backup_tmp_path])
124+
try:
125+
with open(backup_tmp_path, "r") as file:
126+
json.load(file)
127+
os.rename(backup_tmp_path, backup_path) # atomic opetation
128+
except:
129+
self.local.add_log("Could not update backup, backup_tmp file is broken", "warning")
130+
os.remove(backup_tmp_path)
124131
#end define
125132

126133
def GetVarFromWorkerOutput(self, text, search):

0 commit comments

Comments
 (0)