Repository navigation
Only require --force when the --output file exists - #67
Open
jqnatividad wants to merge 3 commits into
Open
jqnatividad wants to merge 3 commits into
jqnatividad wants to merge 3 commits into
Conversation
`sign` and `unsign` refused any `--output` without `--force`, even when
the file did not exist, contradicting both the `--force` help text
("Overwrite output file if it exists") and the "output exists" error.
Without `--force`, the temporary file is now moved into place with
`persist_noclobber`, which atomically fails if the output exists, so a
file created in the meantime is never replaced. This matches
`gen-key`, which uses `create_new(!force)`. With `--force`, or when
signing in place, the behavior is unchanged.
Add CLI tests for both commands: a new output needs no `--force`, an
existing one is refused and left untouched, and `--force` replaces it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
zipsign signandzipsign unsignrefuse any-o/--outputunless-f/--forceis also given, even when the output file doesn't exist:This contradicts the
--forcehelp text ("Overwrite output file if it exists") and the error message itself. The check added in e8388e7 never tests whether the file exists. Signing in place (no-o) isn't affected, which is probably why this went unnoticed.Fix
Without
--force, the temporary file is moved into place with tempfile'sTempPath::persist_noclobberinstead ofrename. That call atomically fails if the output exists, and the failure maps to the existingError::Exists. A plainexists()check would leave a window where a file created between the check and the rename gets overwritten.This matches
gen-key, which already usescreate_new(!force). With--force, or when signing in place, behavior is unchanged. It's a bug fix with no breaking change, so it could ship in a 0.2.x patch. It's independent of #66 (no overlapping files).Also fixes the error's grammar: "output exists, use
--forceallow replacing a file" → "output exists, use--forceto replace it".Testing
New
cli/tests/output_force.rsruns the built binary for bothsignandunsign:-oto a new file succeeds without-f.-oto an existing file without-fis refused with "output exists", and the file is left untouched.-oto an existing file with-freplaces it.Both tests fail on
main(the first-oalready errors) and pass with this change.cargo clippy --all-targets --all-featuresandcargo fmtare clean. In-place sign/verify/unsign still works and leaves no temp files behind.🤖 Generated with Claude Code