Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def __init__(self, app, backup_location, backup_vm, passphrase, *,
# due to possible location in ~/QubesIncoming, the prefix should not be
# a valid VM name
os.makedirs(tmpdir, exist_ok=True)
self.tmpdir = tempfile.mkdtemp(prefix="backup#restore-", dir=tmpdir)
self.tmpdir = tempfile.mkdtemp(prefix=".backup#restore-", dir=tmpdir)

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

def __del__(self):
"""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.
"""
if self.log.getEffectiveLevel() > logging.DEBUG:
if os.path.exists(self.tmpdir):
shutil.rmtree(self.tmpdir)

def _start_retrieval_process(self, filelist, limit_count, limit_bytes):
"""Retrieve backup stream and extract it to :py:attr:`tmpdir`

Expand Down
4 changes: 4 additions & 0 deletions qubesadmin/tests/backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def restore_backup(self, source=None, appvm=None, options=None,
'\n'.join(errors))
if not appvm and not os.path.isdir(backupfile):
os.unlink(backupfile)
tmpdir = getattr(restore_op, "tmpdir", None)
del restore_op
if tmpdir:
self.assertFalse(os.path.exists(tmpdir))

def create_sparse(self, path, size, signature=b''):
with open(path, "wb") as f_img:
Expand Down
2 changes: 1 addition & 1 deletion qubesadmin/tests/backup/backupcompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ def test_230_r4_compressed(self):

@unittest.skipUnless(shutil.which('scrypt'),
"scrypt not installed")
def test_230_r4_custom_cmpression(self):
def test_230_r4_custom_compression(self):
self.create_v4_backup("bzip2")

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