]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Deduplicate paths in rmtree()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 4 Apr 2024 09:02:58 +0000 (11:02 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 4 Apr 2024 09:29:19 +0000 (11:29 +0200)
mkosi/tree.py

index 1b6f651180bf9ba8cf56dabd6431f8b9ad20c1d6..c774579ab8db24b100bef32a0f9aa4f0f2b08f09 100644 (file)
@@ -149,7 +149,7 @@ def rmtree(*paths: Path, tools: Path = Path("/"), sandbox: SandboxProtocol = nos
     if not paths:
         return
 
-    if find_binary("btrfs", root=tools) and (subvolumes := [p for p in paths if is_subvolume(p)]):
+    if find_binary("btrfs", root=tools) and (subvolumes := sorted({p for p in paths if is_subvolume(p)})):
         # Silence and ignore failures since when not running as root, this will fail with a permission error unless the
         # btrfs filesystem is mounted with user_subvol_rm_allowed.
         run(["btrfs", "subvolume", "delete", *subvolumes],
@@ -158,10 +158,10 @@ def rmtree(*paths: Path, tools: Path = Path("/"), sandbox: SandboxProtocol = nos
             stdout=subprocess.DEVNULL if not ARG_DEBUG.get() else None,
             stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None)
 
-    paths = tuple(p for p in paths if p.exists())
-    if paths:
-        run(["rm", "-rf", "--", *paths],
-            sandbox=sandbox(mounts=[Mount(p.parent, p.parent) for p in paths]))
+    filtered = sorted({p for p in paths if p.exists()})
+    if filtered:
+        run(["rm", "-rf", "--", *filtered],
+            sandbox=sandbox(mounts=[Mount(p.parent, p.parent) for p in filtered]))
 
 
 def move_tree(