Skip to content

Commit 2977185

Browse files
committed
delete old auto backups
1 parent 5ac0501 commit 2977185

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

mytoncore/mytoncore.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,29 +1459,32 @@ def ElectionEntry(self, args=None):
14591459

14601460
#end define
14611461

1462-
def clear_tmp(self):
1462+
def clear_dir(self, dir_name):
14631463
start = time.time()
14641464
count = 0
14651465
week_ago = 60 * 60 * 24 * 7
1466-
dir = self.tempDir
1467-
for f in os.listdir(dir):
1468-
ts = os.path.getmtime(os.path.join(dir, f))
1466+
for f in os.listdir(dir_name):
1467+
ts = os.path.getmtime(os.path.join(dir_name, f))
14691468
if ts < time.time() - week_ago:
14701469
count += 1
1471-
os.remove(os.path.join(dir, f))
1470+
os.remove(os.path.join(dir_name, f))
1471+
self.local.add_log(f"Removed {count} old files from {dir_name} directory for {int(time.time() - start)} seconds", "info")
14721472

1473-
self.local.add_log(f"Removed {count} old files from tmp dir for {int(time.time() - start)} seconds", "info")
1473+
def clear_tmp(self):
1474+
self.clear_dir(self.tempDir)
14741475

14751476
def make_backup(self, election_id: str):
14761477
if not self.local.db.get("auto_backup"):
14771478
return
14781479
from mytonctrl.mytonctrl import create_backup
14791480
args = []
14801481
name = f"/mytonctrl_backup_elid{election_id}.zip"
1482+
backups_dir = self.tempDir + "/auto_backups"
14811483
if self.local.db.get("auto_backup_path"):
1482-
args.append(self.local.db.get("auto_backup_path") + name)
1483-
else:
1484-
args.append(self.tempDir + "/backups" + name)
1484+
backups_dir = self.local.db.get("auto_backup_path")
1485+
os.makedirs(self.tempDir + "/auto_backups", exist_ok=True)
1486+
args.append(backups_dir + name)
1487+
self.clear_dir(backups_dir)
14851488
create_backup(self.local, self, args + ['-y'])
14861489

14871490
def GetValidatorKeyByTime(self, startWorkTime, endWorkTime):

0 commit comments

Comments
 (0)