parsing: add parse_location_into_parts

New fucntion returns tuple of 'root' and relative 'file path', which could be
useful in contexts, where knowing 'root' is required, for example setting
selinux labels.
This commit is contained in:
Nikita Dubrovskii 2024-10-18 12:28:32 +02:00 committed by Michael Vogt
parent a699d05094
commit 077244e3b9
2 changed files with 34 additions and 6 deletions

View file

@ -48,18 +48,31 @@ def test_parse_location_mounts():
"root": {
"path": "/run/osbuild/mounts/.",
},
"boot": {
"path": "/run/osbuild/mounts/boot"
}
},
}
location = "mount://root/"
root, path = parsing.parse_location_into_parts(location, args)
assert [root, path] == ["/run/osbuild/mounts/.", "/"]
path = parsing.parse_location(location, args)
assert path == "/run/osbuild/mounts/."
location = "mount://boot/efi/EFI/Linux"
root, path = parsing.parse_location_into_parts(location, args)
assert [root, path] == ["/run/osbuild/mounts/boot", "/efi/EFI/Linux"]
path = parsing.parse_location(location, args)
assert path == "/run/osbuild/mounts/boot/efi/EFI/Linux"
def test_parse_location_tree():
args = {
"tree": "/run/osbuild/tree",
}
location = "tree:///disk.img"
root, path = parsing.parse_location_into_parts(location, args)
assert [root, path] == ["/run/osbuild/tree", "/disk.img"]
path = parsing.parse_location(location, args)
assert path == "/run/osbuild/tree/disk.img"
@ -73,5 +86,7 @@ def test_parse_location_inputs():
},
}
location = "input://tree/"
root, path = parsing.parse_location_into_parts(location, args)
assert [root, path] == ["/run/osbuild/inputs/tree", "/"]
path = parsing.parse_location(location, args)
assert path == "/run/osbuild/inputs/tree/."