Skip to content

Commit 08f6820

Browse files
committed
Assure backup restore/verify tmpdir is properly deleted
Since deleting tmp directory in `restore_do` does not work properly (this is confirmed by the unittests), we check for its existence again once more and delete it if it still exists. fixes: QubesOS/qubes-issues#9387
1 parent 02a9b4f commit 08f6820

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

qubesadmin/backup/restore.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def __init__(self, app, backup_location, backup_vm, passphrase, *,
956956
# due to possible location in ~/QubesIncoming, the prefix should not be
957957
# a valid VM name
958958
os.makedirs(tmpdir, exist_ok=True)
959-
self.tmpdir = tempfile.mkdtemp(prefix="backup#restore-", dir=tmpdir)
959+
self.tmpdir = tempfile.mkdtemp(prefix=".backup#restore-", dir=tmpdir)
960960

961961
#: list of processes (Popen objects) to kill on cancel
962962
self.processes_to_kill_on_cancel = []
@@ -977,6 +977,15 @@ def __init__(self, app, backup_location, backup_vm, passphrase, *,
977977
#: VMs included in the backup
978978
self.backup_app = self._process_qubes_xml()
979979

980+
def __del__(self):
981+
"""Since deleting tmp directory in `restore_do` does not work properly
982+
(this is confirmed by the unittests), we check for its existence again
983+
once more and delete it if it still exists.
984+
"""
985+
if self.log.getEffectiveLevel() > logging.DEBUG:
986+
if os.path.exists(self.tmpdir):
987+
shutil.rmtree(self.tmpdir)
988+
980989
def _start_retrieval_process(self, filelist, limit_count, limit_bytes):
981990
"""Retrieve backup stream and extract it to :py:attr:`tmpdir`
982991

qubesadmin/tests/backup/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def restore_backup(self, source=None, appvm=None, options=None,
193193
'\n'.join(errors))
194194
if not appvm and not os.path.isdir(backupfile):
195195
os.unlink(backupfile)
196+
tmpdir = getattr(restore_op, "tmpdir", None)
197+
del restore_op
198+
if tmpdir:
199+
self.assertFalse(os.path.exists(tmpdir))
196200

197201
def create_sparse(self, path, size, signature=b''):
198202
with open(path, "wb") as f_img:

qubesadmin/tests/backup/backupcompatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ def test_230_r4_compressed(self):
19051905

19061906
@unittest.skipUnless(shutil.which('scrypt'),
19071907
"scrypt not installed")
1908-
def test_230_r4_custom_cmpression(self):
1908+
def test_230_r4_custom_compression(self):
19091909
self.create_v4_backup("bzip2")
19101910

19111911
self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = (

0 commit comments

Comments
 (0)