From b7bf377db5187f41648dac013fbebc5805aeaa9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 11 Nov 2018 01:12:00 +0100 Subject: [PATCH] backup: fix naming qubes.xml.000 in the archive Restore old code for calculating subdir within the archive. The new one had two problems: - set '/' for empty input subdir - which caused qubes.xml.000 to be named '/qubes.xml.000' (and then converted to '../../qubes.xml.000'); among other things, this results in the wrong path used for encryption passphrase - resolved symlinks, which breaks calculating path for any symlinks within VM's directory (symlinks there should be treated as normal files to be sure that actual content is included in the backup) This partially reverts 4e49b951ceeaa6b081062f4acdea7e7f2c771300. Fixes QubesOS/qubes-issues#4493 --- qubes/backup.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index 82984831c..bafaf6bae 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -260,14 +260,17 @@ def __init__(self, file_path, subdir=None, name=None, size=None): size = qubes.storage.file.get_disk_usage(file_path) if subdir is None: - abs_file_dir = pathlib.Path(file_path).resolve().parent - abs_base_dir = pathlib.Path( - qubes.config.system_path["qubes_base_dir"]).resolve() - # this raises ValueError if abs_file_dir is not in abs_base_dir - subdir = str(abs_file_dir.relative_to(abs_base_dir)) - - if not subdir.endswith(os.path.sep): - subdir += os.path.sep + abs_file_path = os.path.abspath(file_path) + abs_base_dir = os.path.abspath( + qubes.config.system_path["qubes_base_dir"]) + '/' + abs_file_dir = os.path.dirname(abs_file_path) + '/' + (nothing, directory, subdir) = \ + abs_file_dir.partition(abs_base_dir) + assert nothing == "" + assert directory == abs_base_dir + else: + if subdir and not subdir.endswith('/'): + subdir += '/' #: real path to the file self.path = file_path