From 2948cf3e49c1e47ff92f5bf3f1ebba2577e7ffba Mon Sep 17 00:00:00 2001 From: MoonEyes <14891700+MoonEyes@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:47:43 +0100 Subject: [PATCH] awc_shorts: refuse a catalog collision before creating the output folder Review follow-up from #934: the bank export directory check ran after os.makedirs, so a refused run left an empty output folder. Both collision checks now run first, and a test checks that out/ is not created. Co-Authored-By: Claude Opus 5.5 --- tools/awc_shorts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/awc_shorts.py b/tools/awc_shorts.py index 89b31c460..82f3b4a73 100644 --- a/tools/awc_shorts.py +++ b/tools/awc_shorts.py @@ -161,10 +161,15 @@ def main(argv=None) -> int: print(f"awc_shorts: cannot list {e.filename or a.src}: {e.strerror or e}", file=sys.stderr) return 2 catalog = os.path.join(a.out, "shorts.csv") - for path, _ in banks: + # Both refusals run before the output folder is created, so a refused run leaves nothing behind. + for path, bank in banks: if same_report_path(catalog, path): print(f"awc_shorts: error: catalog would overwrite the input bank {path}", file=sys.stderr) return 2 + target = os.path.join(a.out, bank) + if same_report_path(catalog, target): + print(f"awc_shorts: error: catalog would collide with bank export directory {target}", file=sys.stderr) + return 2 try: os.makedirs(a.out, exist_ok=True) except OSError as e: @@ -173,9 +178,6 @@ def main(argv=None) -> int: destinations = {} for path, bank in banks: target = os.path.join(a.out, bank) - if same_report_path(catalog, target): - print(f"awc_shorts: error: catalog would collide with bank export directory {target}", file=sys.stderr) - return 2 key = path_key(target) if key in destinations: print(f"awc_shorts: error: {destinations[key]} and {path} would both export to {target}", file=sys.stderr)