Skip to content

Commit b3bbeaa

Browse files
DaanDeMeyerbehrmann
authored andcommitted
Handle dangling symlinks in rmtree() and run_clean()
1 parent 752a2fb commit b3bbeaa

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

mkosi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4587,7 +4587,7 @@ def run_clean(args: Args, config: Config, *, resources: Path) -> None:
45874587
outputs = {
45884588
config.output_dir_or_cwd() / output
45894589
for output in config.outputs
4590-
if (config.output_dir_or_cwd() / output).exists()
4590+
if (config.output_dir_or_cwd() / output).exists() or (config.output_dir_or_cwd() / output).is_symlink()
45914591
}
45924592

45934593
# Make sure we resolve the symlink we create in the output directory and remove its target as well as it might

mkosi/tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def rmtree(*paths: Path, sandbox: SandboxProtocol = nosandbox) -> None:
158158
stdout=subprocess.DEVNULL if not ARG_DEBUG.get() else None,
159159
stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None)
160160

161-
filtered = sorted({p for p in paths if p.exists()})
161+
filtered = sorted({p for p in paths if p.exists() or p.is_symlink()})
162162
if filtered:
163163
run(["rm", "-rf", "--", *filtered],
164164
sandbox=sandbox(binary="rm", mounts=[Mount(p.parent, p.parent) for p in filtered]))

0 commit comments

Comments
 (0)