From: Daan De Meyer Date: Thu, 4 Apr 2024 09:02:58 +0000 (+0200) Subject: Deduplicate paths in rmtree() X-Git-Tag: v23~33^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86cefa3f9f97d3b7cce9bb3cae2204dd19fcf951;p=thirdparty%2Fmkosi.git Deduplicate paths in rmtree() --- diff --git a/mkosi/tree.py b/mkosi/tree.py index 1b6f65118..c774579ab 100644 --- a/mkosi/tree.py +++ b/mkosi/tree.py @@ -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(