Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,24 @@ def CheckConfigFile(self, fift, liteClient):
subprocess.run(args)
self.dbFile = mconfig_path
self.Refresh()
elif os.path.isfile(backup_path) == False:
self.local.add_log("Create backup config file", "info")
args = ["cp", mconfig_path, backup_path]
subprocess.run(args)
elif not os.path.isfile(backup_path) or time.time() - os.path.getmtime(backup_path) > 3600:
self.local.try_function(self.create_self_db_backup)
#end define

def create_self_db_backup(self):
self.local.add_log("Create backup config file", "info")
mconfig_path = self.local.buffer.db_path
backup_path = mconfig_path + ".backup"
backup_tmp_path = backup_path + '.tmp'
subprocess.run(["cp", mconfig_path, backup_tmp_path])
try:
with open(backup_tmp_path, "r") as file:
json.load(file)
os.rename(backup_tmp_path, backup_path) # atomic opetation
except:
self.local.add_log("Could not update backup, backup_tmp file is broken", "warning")
os.remove(backup_tmp_path)

def GetVarFromWorkerOutput(self, text, search):
if ':' not in search:
search += ':'
Expand Down Expand Up @@ -3037,6 +3049,7 @@ def SetSettings(self, name, data):
except: pass
self.local.db[name] = data
self.local.save()
self.create_self_db_backup()
#end define

def migrate_to_modes(self):
Expand Down