From 3ba48de8bce8c7fcb0ea81cee32c73022508e56c Mon Sep 17 00:00:00 2001 From: Bill Wallis Date: Fri, 10 Apr 2026 17:34:40 +0100 Subject: [PATCH] fix: handle unhappy paths in file copying --- pyproject.toml | 1 + tools/apply.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cba4fb9..6a3a6d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ version = "0.0.0" description = "" authors = [{name = "billwallis"}] readme = "README.md" +license = {file = "LICENSE"} requires-python = ">=3.13" dependencies = [] diff --git a/tools/apply.py b/tools/apply.py index e9a9eb5..dce5895 100644 --- a/tools/apply.py +++ b/tools/apply.py @@ -16,6 +16,14 @@ ] +def _copy_file_to_target( + source: pathlib.Path, + destination: pathlib.Path, +) -> None: + destination.parent.mkdir(parents=True, exist_ok=True) + shutil.copy(source, destination) + + def copy_files_to_target(target: pathlib.Path) -> int: if not target.exists(): logging.error(f"target {target} does not exist") @@ -24,10 +32,15 @@ def copy_files_to_target(target: pathlib.Path) -> int: logging.error(f"target {target} is not a directory") return FAILURE + ret = SUCCESS for file in FILES_TO_COPY: - shutil.copy(ROOT / file, target / file) + try: + _copy_file_to_target(source=ROOT / file, destination=target / file) + except Exception as e: + logging.error(str(e)) + ret = FAILURE - return SUCCESS + return ret def main(argv: Sequence[str] | None = None) -> int: @@ -43,7 +56,7 @@ def main(argv: Sequence[str] | None = None) -> int: if not args.targets: parser.print_help() for target in args.targets: - ret |= copy_files_to_target(target=pathlib.Path(target)) + ret |= copy_files_to_target(target=pathlib.Path(target).resolve()) return ret