Repository navigation
fix(cli): refuse an --output path that already exists - #2217
Conversation
An explicit --output path was opened with os.Create, silently truncating any existing file (including a previous report or the --input-csv file). validateFilePaths only checked the parent directory. Fail validation when the path exists (file, directory or symlink, detected with Lstat so a dangling symlink cannot be followed and overwritten) and on any stat error other than not-exist. The message names the path and tells the operator to pick a new path or remove the old file. Auto-generated timestamped filenames do not set CSVOutput and are unaffected. --input-csv equal to --output now fails with the same message. Closes #2050 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 5 billable files and costs up to $1.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 37 minutes for your next included review. View limit details
Comment |
Independent review verdict: CLEAN at 2e13d2cReviewer: fresh Claude agent (Sonnet, high effort), not the author, cold brief. The PR body was treated as a claim. Coordinator: claude-cc-reviewer. Blocking findings: none. Non-blocking notes (possible follow-ups):
What was attacked and how (local macOS,
Gate:
|
Closes #2050
Summary
An explicit
--output <path>that already existed was silently truncated byos.Create. That meant a rerun with the same path destroyed the previous purchase report. This matters most on the--input-csvpath, which writes no audit records.validateFilePaths(cmd/validators.go) now refuses an explicit--outputpath that already exists. The message isoutput path already exists: <path> (it would be overwritten); choose a new --output path or remove the existing file.os.Lstat, so a file, a directory or a symlink is refused. A dangling symlink is refused too, becauseos.Createwould follow it.validateFlags, the root command'sPreRunE. That means it runs before any fetch, purchase or file creation.generateCSVFilenamereturnsCSVOutputonly when--outputis set.--input-csvand--outputnow fails with the same message.CHANGELOG.md,README.mdanddocs/cli/README.mddocument the refusal.Behaviour change: a script that reruns with the same explicit
--outputpath now fails at validation. It needs a new path, or must remove the old file first. No in-repo script, Makefile target or CI step usescudly --output.Evidence (local, macOS,
GOTOOLCHAIN=go1.26.9; unit tests on real temp files)validators.gochange stashed, four newTestValidateFilePathssubtests fail: existing file, existing directory, dangling symlink, and input equal to output. With the change restored, they pass.LstatforStatfails the dangling-symlink subtest.make build: OK.go vet ./...: clean.go test -race ./cmd/...: pass, with no existing tests changed.scripts/test-git-secrets-allowlist.sh: 44/44.🤖 Generated with Claude Code