parsing: treat locations without scheme as belonging to 'tree://'
This commit is contained in:
parent
077244e3b9
commit
6a59e740e4
3 changed files with 42 additions and 7 deletions
|
|
@ -77,11 +77,15 @@ def parse_location_into_parts(location: str, args: Dict) -> Tuple[str, str]:
|
|||
Parses the location URL to derive the corresponding root and url path.
|
||||
|
||||
Parameters:
|
||||
- location (str): The location URL to be parsed.
|
||||
- location (str): The location URL to be parsed. If the URL has no scheme,
|
||||
then 'tree://' is implied
|
||||
- args (Dict): A dictionary containing arguments including mounts and
|
||||
path information as passed by osbuild.api.arguments()
|
||||
"""
|
||||
|
||||
if "://" not in location:
|
||||
location = f"tree://{location}"
|
||||
|
||||
url = urlparse(location)
|
||||
|
||||
scheme = url.scheme
|
||||
|
|
|
|||
|
|
@ -15,12 +15,9 @@ def main(args):
|
|||
parents = item.get("parents", False)
|
||||
exist_ok = item.get("exist_ok", False)
|
||||
|
||||
if "://" not in path:
|
||||
if not path.startswith("/"):
|
||||
print("WARNING: relative path used, this is discouraged!")
|
||||
path = f"tree:///{path}"
|
||||
else:
|
||||
path = f"tree://{path}"
|
||||
if "://" not in path and not path.startswith("/"):
|
||||
print("WARNING: relative path used, this is discouraged!")
|
||||
path = f"tree:///{path}"
|
||||
|
||||
target = parsing.parse_location(path, args)
|
||||
if parents:
|
||||
|
|
|
|||
|
|
@ -90,3 +90,37 @@ def test_parse_location_inputs():
|
|||
assert [root, path] == ["/run/osbuild/inputs/tree", "/"]
|
||||
path = parsing.parse_location(location, args)
|
||||
assert path == "/run/osbuild/inputs/tree/."
|
||||
|
||||
|
||||
def test_parse_location_abspath():
|
||||
args = {
|
||||
"tree": "/run/osbuild/tree",
|
||||
}
|
||||
location = "/path/to/file"
|
||||
root, path = parsing.parse_location_into_parts(location, args)
|
||||
assert [root, path] == ["/run/osbuild/tree", "/path/to/file"]
|
||||
path = parsing.parse_location(location, args)
|
||||
assert path == "/run/osbuild/tree/path/to/file"
|
||||
|
||||
|
||||
def test_parse_location_badpath():
|
||||
args = {
|
||||
"tree": "/run/osbuild/tree",
|
||||
"paths": {
|
||||
"mounts": "/run/osbuild/mounts",
|
||||
},
|
||||
"mounts": {
|
||||
"root": {
|
||||
"path": "/run/osbuild/mounts/."
|
||||
}
|
||||
},
|
||||
}
|
||||
location = "file"
|
||||
with pytest.raises(ValueError) as ex:
|
||||
parsing.parse_location_into_parts(location, args)
|
||||
assert "url.path from location must start with '/'" in str(ex.value)
|
||||
|
||||
location = "mount://disk/file"
|
||||
with pytest.raises(ValueError) as ex:
|
||||
parsing.parse_location_into_parts(location, args)
|
||||
assert "Unknown mount" in str(ex.value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue