From ba3a098c3b82d0dcf36198e67ae3bcd6ad7c6d4a Mon Sep 17 00:00:00 2001 From: scarf Date: Sun, 18 Feb 2024 21:48:43 +0900 Subject: [PATCH] virtinst: disk: strip away `file://` protocol --- tests/test_cli.py | 1 + virtinst/devices/disk.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 27c222deb..c42457897 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -929,6 +929,7 @@ c = vinst.add_category("storage", "--pxe --nographics --noautoconsole --hvm --os c.add_valid("--disk %(COLLIDE)s --check path_in_use=off") # Colliding storage with --check c.add_valid("--disk %(COLLIDE)s --force") # Colliding storage with --force c.add_valid("--disk %(NEWIMG1)s,sparse=true,size=100000000 --check disk_size=off") # Don't warn about fully allocated file exceeding disk space +c.add_valid("--disk file://%(NEWIMG1)s,size=1") # Check that 'file://' prefix is removed correctly c.add_invalid("--disk /dev/zero --nodisks", grep="Cannot specify storage and use --nodisks") c.add_invalid("--file %(NEWIMG1)s --file-size 100000 --nonsparse", grep="There is not enough free space") # Nonexisting file, size too big c.add_invalid("--file %(NEWIMG1)s --file-size 100000", grep="The requested volume capacity will exceed the") # Huge file, sparse, but no prompting diff --git a/virtinst/devices/disk.py b/virtinst/devices/disk.py index 9609ebacf..be2147e3e 100644 --- a/virtinst/devices/disk.py +++ b/virtinst/devices/disk.py @@ -636,6 +636,11 @@ class DeviceDisk(Device): return self._storage_backend.get_path() def set_source_path(self, newpath): + # Some file managers use 'file://' when passing files to + # virt-manager, we need to strip it from the newpath. + if newpath is not None: + newpath = newpath.removeprefix("file://") + if self._storage_backend.will_create_storage(): raise xmlutil.DevError( "Can't change disk path if storage creation info "