From 76bddaa28094b13bdd3d9bc4fde4da7d7a1b5fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 4 Sep 2015 00:19:40 +0200 Subject: [PATCH] core: use vm.absolute_path to parse paths in qubes.xml This makes easier to handle some corner cases. One of them is having entry without `dir_path` defined. This may happen when migrating from R2 (using backup+restore or in-place) while some DisposableVM was running (even if not included in the backup itself). Fixes qubesos/qubes-issues#1124 Reported by @doncohen, thanks @wyory for providing more details. --- core-modules/000QubesVm.py | 7 ++++++- core/storage/__init__.py | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index ccf56a4f..1cc8d212 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -376,8 +376,13 @@ class QubesVm(object): def absolute_path(self, arg, default): if arg is not None and os.path.isabs(arg): return arg - else: + elif self.dir_path is not None: return os.path.join(self.dir_path, (arg if arg is not None else default)) + else: + # cannot provide any meaningful value without dir_path; this is + # only to import some older format of `qubes.xml` (for example + # during migration from older release) + return None def _absolute_path_gen(self, default): return lambda value: self.absolute_path(value, default) diff --git a/core/storage/__init__.py b/core/storage/__init__.py index 41f3e73f..3a12dbe6 100644 --- a/core/storage/__init__.py +++ b/core/storage/__init__.py @@ -55,12 +55,12 @@ class QubesVmStorage(object): else: self.root_img_size = defaults['root_img_size'] - self.private_img = os.path.join(self.vmdir, vm_files["private_img"]) + self.private_img = vm.absolute_path(vm_files["private_img"], None) if self.vm.template: self.root_img = self.vm.template.root_img else: - self.root_img = os.path.join(self.vmdir, vm_files["root_img"]) - self.volatile_img = os.path.join(self.vmdir, vm_files["volatile_img"]) + self.root_img = vm.absolute_path(vm_files["root_img"], None) + self.volatile_img = vm.absolute_path(vm_files["volatile_img"], None) # For now compute this path still in QubesVm self.modules_img = modules_img