Skip to content

Commit

Permalink
Remove empty directories from extension images
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanDeMeyer committed Jan 19, 2025
1 parent 3392686 commit ff387dd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,18 @@ def mount_base_trees(context: Context) -> Iterator[None]:
def remove_files(context: Context) -> None:
"""Remove files based on user-specified patterns"""

if not context.config.remove_files and not (context.root / "work").exists():
return
if context.config.remove_files or (context.root / "work").exists():
with complete_step("Removing files…"):
remove = flatten(
context.root.glob(pattern.lstrip("/")) for pattern in context.config.remove_files
)
rmtree(*remove, context.root / "work", sandbox=context.sandbox)

with complete_step("Removing files…"):
remove = flatten(context.root.glob(pattern.lstrip("/")) for pattern in context.config.remove_files)
rmtree(*remove, context.root / "work", sandbox=context.sandbox)
if context.config.output_format.is_extension_image():
with complete_step("Removing empty directories…"):
for d in reversed(sorted(context.root.glob("**/"))):
if not any(d.iterdir()):
d.rmdir()


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

0 comments on commit ff387dd

Please sign in to comment.