Skip to content

Commit

Permalink
Use os.walk() to remove empty directories
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanDeMeyer committed Jan 20, 2025
1 parent c42ef66 commit 090e543
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ def remove_files(context: Context) -> None:

if context.config.output_format.is_extension_image():
with complete_step("Removing empty directories…"):
for d in reversed(sorted(context.root.glob("**/"))):
if d == context.root:
continue
for path, dirs, _ in os.walk(context.root, topdown=False):
p = Path(path)

if not any(d.iterdir()):
d.rmdir()
for d in dirs:
t = p / d
if not t.is_symlink() and not any(t.iterdir()):
t.rmdir()


def install_distribution(context: Context) -> None:
Expand Down

0 comments on commit 090e543

Please sign in to comment.