]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use absolute paths everywhere 1438/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 14 Apr 2023 20:48:41 +0000 (22:48 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 15 Apr 2023 06:31:01 +0000 (08:31 +0200)
bwrap seems to run into permission errors with relative paths in
some cases so let's follow systemd best practices and convert all
config paths to absolute paths as we're parsing them.

Fixes #1430

mkosi/__init__.py
mkosi/config.py

index 036c21088fb5c3460323e4d8de5a0ffa6e64fdb5..92e3ffc3fc869aa9563eb356a960f21b71fba059 100644 (file)
@@ -1130,6 +1130,7 @@ def load_args(args: argparse.Namespace) -> MkosiConfig:
             args.output = args.output_dir / args.output
         else:
             warn("Ignoring configured output directory as output file is a qualified path.")
+            args.output = args.output.absolute()
 
     if args.environment:
         env = {}
index bb36af8ec0b7e2371efba8c1171e516cf16c6576..ecf6032f437a2e7d8b194956b5b7d48c979dfef4 100644 (file)
@@ -45,9 +45,9 @@ def parse_source_target_paths(value: str) -> tuple[Path, Optional[Path]]:
     src, _, target = value.partition(':')
     if not Path(src).exists():
         die(f"{src} does not exist")
-    if target and not Path(target).absolute():
+    if target and not Path(target).is_absolute():
         die("Target path must be absolute")
-    return Path(src), Path(target) if target else None
+    return Path(src).absolute(), Path(target) if target else None
 
 
 def config_parse_string(dest: str, value: Optional[str], namespace: argparse.Namespace) -> Optional[str]:
@@ -71,7 +71,7 @@ def config_parse_script(dest: str, value: Optional[str], namespace: argparse.Nam
         if not os.access(value, os.X_OK):
             die(f"{value} is not executable")
 
-    return Path(value) if value else None
+    return Path(value).absolute() if value else None
 
 
 def config_parse_boolean(dest: str, value: Optional[str], namespace: argparse.Namespace) -> bool:
@@ -196,7 +196,7 @@ def make_path_parser(required: bool) -> Callable[[str], Path]:
         if required and not Path(value).exists():
             die(f"{value} does not exist")
 
-        return Path(value)
+        return Path(value).absolute()
 
     return parse_path
 
@@ -209,7 +209,7 @@ def config_make_path_parser(required: bool) -> ConfigParseCallback:
         if value and required and not Path(value).exists():
             die(f"{value} does not exist")
 
-        return Path(value) if value else None
+        return Path(value).absolute() if value else None
 
     return config_parse_path