From f023b3dd6e1ddc0280e1f0096cdff1a6c5ad00fc 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index 82984831..1364e5a7 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -29,7 +29,6 @@ import grp import itertools import logging import os -import pathlib import pwd import re import shutil @@ -260,14 +259,17 @@ class Backup: 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