Skip to content

Commit 82913df

Browse files
committed
Fix qcow2 support for absolute backing_file paths
_open_backing_file assumed that the backing_file path was always a filename relative to the snapshot path. Using .with_name() to concat the whole path broke the use case for absolute path for the backing_file causing ValueError("Invalid name ..."). This change updates the logic to detect whether auto_backing_file is an absolute path. If so, it is used directly; otherwise we fall back to constructing the path relative to the snapshot location. This will support the following use-cases: backing file: /home/user/workdir/ubuntu-22.04.qcow2 backing file: ubuntu-22.04.qcow2 backing file: ./ubuntu-22.04-packer.qcow2 backing file: ../../ubuntu-22.04-packer.qcow2 Fixes: #64 Signed-off-by: Andreia Ocanoaia <[email protected]>
1 parent 2e2d0aa commit 82913df

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

dissect/hypervisor/disk/qcow2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ def _open_backing_file(self, backing_file: BinaryIO | None, allow_no_backing_fil
188188
backing_file_path = None
189189
if backing_file is None:
190190
if self.path:
191-
if (backing_file_path := self.path.with_name(self.auto_backing_file)).exists():
191+
auto_backing_path = Path(self.auto_backing_file)
192+
backing_file_path = (
193+
auto_backing_path
194+
if auto_backing_path.is_absolute()
195+
else self.path.with_name(auto_backing_path.name)
196+
)
197+
if backing_file_path.exists():
192198
backing_file = backing_file_path.open("rb")
193199
elif not allow_no_backing_file:
194200
raise Error(

0 commit comments

Comments
 (0)