From: Daan De Meyer Date: Mon, 29 Jul 2024 10:14:43 +0000 (+0200) Subject: Handle dangling symlinks in rmtree() and run_clean() X-Git-Tag: v24.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3bbeaa19299ae30e6d2401102af41d283de74e3;p=thirdparty%2Fmkosi.git Handle dangling symlinks in rmtree() and run_clean() --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index ae9a93714..edc9784c6 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4587,7 +4587,7 @@ def run_clean(args: Args, config: Config, *, resources: Path) -> None: outputs = { config.output_dir_or_cwd() / output for output in config.outputs - if (config.output_dir_or_cwd() / output).exists() + if (config.output_dir_or_cwd() / output).exists() or (config.output_dir_or_cwd() / output).is_symlink() } # Make sure we resolve the symlink we create in the output directory and remove its target as well as it might diff --git a/mkosi/tree.py b/mkosi/tree.py index 82154d8aa..f35bca1a1 100644 --- a/mkosi/tree.py +++ b/mkosi/tree.py @@ -158,7 +158,7 @@ def rmtree(*paths: Path, sandbox: SandboxProtocol = nosandbox) -> None: stdout=subprocess.DEVNULL if not ARG_DEBUG.get() else None, stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None) - filtered = sorted({p for p in paths if p.exists()}) + filtered = sorted({p for p in paths if p.exists() or p.is_symlink()}) if filtered: run(["rm", "-rf", "--", *filtered], sandbox=sandbox(binary="rm", mounts=[Mount(p.parent, p.parent) for p in filtered]))