]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Have all tree functions return the destination path
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jan 2024 07:32:40 +0000 (08:32 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jan 2024 13:24:43 +0000 (14:24 +0100)
mkosi/tree.py

index 19afc98c8f50959df04da84411cf09a8f4290284..2bee42ef564facae8acaf76faf86d8fc4cf2224e 100644 (file)
@@ -29,7 +29,7 @@ def make_tree(
     use_subvolumes: ConfigFeature = ConfigFeature.disabled,
     tools: Path = Path("/"),
     sandbox: Sequence[PathString] = (),
-) -> None:
+) -> Path:
     if use_subvolumes == ConfigFeature.enabled and not find_binary("btrfs", root=tools):
         die("Subvolumes requested but the btrfs command was not found")
 
@@ -38,7 +38,7 @@ def make_tree(
             die(f"Subvolumes requested but {path} is not located on a btrfs filesystem")
 
         path.mkdir()
-        return
+        return path
 
     if use_subvolumes != ConfigFeature.disabled and find_binary("btrfs", root=tools) is not None:
         result = run(["btrfs", "subvolume", "create", path],
@@ -49,6 +49,8 @@ def make_tree(
     if result != 0:
         path.mkdir()
 
+    return path
+
 
 @contextlib.contextmanager
 def preserve_target_directories_stat(src: Path, dst: Path) -> Iterator[None]:
@@ -74,7 +76,7 @@ def copy_tree(
     use_subvolumes: ConfigFeature = ConfigFeature.disabled,
     tools: Path = Path("/"),
     sandbox: Sequence[PathString] = (),
-) -> None:
+) -> Path:
     subvolume = (use_subvolumes == ConfigFeature.enabled or
                  use_subvolumes == ConfigFeature.auto and find_binary("btrfs", root=tools) is not None)
 
@@ -110,7 +112,7 @@ def copy_tree(
             else contextlib.nullcontext()
         ):
             run(copy, sandbox=sandbox)
-        return
+        return dst
 
     # btrfs can't snapshot to an existing directory so make sure the destination does not exist.
     if dst.exists():
@@ -126,6 +128,8 @@ def copy_tree(
         ):
             run(copy, sandbox=sandbox)
 
+    return dst
+
 
 def rmtree(*paths: Path, sandbox: Sequence[PathString] = ()) -> None:
     if paths:
@@ -139,9 +143,9 @@ def move_tree(
     use_subvolumes: ConfigFeature = ConfigFeature.disabled,
     tools: Path = Path("/"),
     sandbox: Sequence[PathString] = (),
-) -> None:
+) -> Path:
     if src == dst:
-        return
+        return dst
 
     if dst.is_dir():
         dst = dst / src.name
@@ -154,3 +158,5 @@ def move_tree(
 
         copy_tree(src, dst, use_subvolumes=use_subvolumes, tools=tools, sandbox=sandbox)
         rmtree(src, sandbox=sandbox)
+
+    return dst