Quellcode durchsuchen

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
Marek Marczykowski-Górecki vor 5 Jahren
Ursprung
Commit
f023b3dd6e
1 geänderte Dateien mit 11 neuen und 9 gelöschten Zeilen
  1. 11 9
      qubes/backup.py

+ 11 - 9
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