]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Speed up empty_directory()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 Nov 2023 16:36:27 +0000 (17:36 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 Nov 2023 16:51:54 +0000 (17:51 +0100)
Let's invoke rm once instead of N times.

mkosi/__init__.py
mkosi/tree.py

index 909657b25c536feecdfb8058bd0a702570f36216..19350f34db3cf8645595991c9c1ce3d2c5c5b567 100644 (file)
@@ -1603,8 +1603,7 @@ def print_output_size(path: Path) -> None:
 
 def empty_directory(path: Path) -> None:
     try:
-        for f in os.listdir(path):
-            rmtree(path / f)
+        rmtree(*path.iterdir())
     except FileNotFoundError:
         pass
 
index 952c75646e7d3f4ad3490e69192580c4f05611bd..063361a0844dd6c5ed41b2c4c889c2dca4e6d1d1 100644 (file)
@@ -83,8 +83,8 @@ def copy_tree(config: MkosiConfig, src: Path, dst: Path, *, preserve_owner: bool
         run(copy)
 
 
-def rmtree(path: Path) -> None:
-    run(["rm", "-rf", "--", path])
+def rmtree(*paths: Path) -> None:
+    run(["rm", "-rf", "--", *paths])
 
 
 def move_tree(config: MkosiConfig, src: Path, dst: Path) -> None: