From 94e76644c42ee88072dfdedfe1f5ec251559065a Mon Sep 17 00:00:00 2001 From: Marc Cousin Date: Sun, 14 Aug 2022 20:42:00 +0200 Subject: [PATCH] Cleanup temp files. By @marco44 (#1384) --- src/vorta/borg/borg_job.py | 4 ++++ src/vorta/borg/create.py | 3 ++- src/vorta/borg/extract.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vorta/borg/borg_job.py b/src/vorta/borg/borg_job.py index 83551327..cee62ff5 100644 --- a/src/vorta/borg/borg_job.py +++ b/src/vorta/borg/borg_job.py @@ -104,6 +104,7 @@ class BorgJob(JobInterface, BackupProfileMixin): self.cwd = params.get('cwd', None) self.params = params self.process = None + self.cleanup_files = params.get('cleanup_files', []) def repo_id(self): return self.site_id @@ -182,6 +183,7 @@ class BorgJob(JobInterface, BackupProfileMixin): ret['profile_id'] = profile.id ret['ok'] = True + ret['cleanup_files'] = [] return ret @@ -299,6 +301,8 @@ class BorgJob(JobInterface, BackupProfileMixin): self.process_result(result) self.finished_event(result) + for tmpfile in self.cleanup_files: + tmpfile.close() def process_result(self, result): pass diff --git a/src/vorta/borg/create.py b/src/vorta/borg/create.py index f851a092..765825f6 100644 --- a/src/vorta/borg/create.py +++ b/src/vorta/borg/create.py @@ -145,10 +145,11 @@ class BorgCreateJob(BorgJob): exclude_dirs.append(expanded_directory) if exclude_dirs: - pattern_file = tempfile.NamedTemporaryFile('w', delete=False) + pattern_file = tempfile.NamedTemporaryFile('w', delete=True) pattern_file.write('\n'.join(exclude_dirs)) pattern_file.flush() cmd.extend(['--exclude-from', pattern_file.name]) + ret['cleanup_files'].append(pattern_file) if profile.exclude_if_present is not None: for f in profile.exclude_if_present.split('\n'): diff --git a/src/vorta/borg/extract.py b/src/vorta/borg/extract.py index 1fbaecc4..6938bf67 100644 --- a/src/vorta/borg/extract.py +++ b/src/vorta/borg/extract.py @@ -35,7 +35,7 @@ class BorgExtractJob(BorgJob): # dialog. # Unselected (and excluded) parent folders will be restored by borg # but without the metadata stored in the archive. - pattern_file = tempfile.NamedTemporaryFile('w', delete=False) + pattern_file = tempfile.NamedTemporaryFile('w', delete=True) pattern_file.write("P fm\n") indexes = [QModelIndex()] @@ -54,6 +54,7 @@ class BorgExtractJob(BorgJob): pattern_file.flush() pattern_file.close() # wont delete temp file cmd.extend(['--patterns-from', pattern_file.name]) + ret['cleanup_files'].append(pattern_file) ret['ok'] = True ret['cmd'] = cmd