Skip to content

Only require --force when the --output file exists - #67

Open
jqnatividad wants to merge 3 commits into
Kijewski:mainfrom
jqnatividad:fix-output-force
Open

jqnatividad wants to merge 3 commits into
Kijewski:mainfrom
jqnatividad:fix-output-force

Conversation

@jqnatividad

@jqnatividad jqnatividad commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

zipsign sign and zipsign unsign refuse any -o/--output unless -f/--force is also given, even when the output file doesn't exist:

$ zipsign sign zip a.zip priv.key -o new.zip
Error: could not sign file

Caused by:
    output exists, use `--force` allow replacing a file

This contradicts the --force help 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's TempPath::persist_noclobber instead of rename. That call atomically fails if the output exists, and the failure maps to the existing Error::Exists. A plain exists() check would leave a window where a file created between the check and the rename gets overwritten.

This matches gen-key, which already uses create_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 --force allow replacing a file" → "output exists, use --force to replace it".

Testing

  • New cli/tests/output_force.rs runs the built binary for both sign and unsign:

    • -o to a new file succeeds without -f.
    • -o to an existing file without -f is refused with "output exists", and the file is left untouched.
    • -o to an existing file with -f replaces it.

    Both tests fail on main (the first -o already errors) and pass with this change.

  • cargo clippy --all-targets --all-features and cargo fmt are clean. In-place sign/verify/unsign still works and leaves no temp files behind.

🤖 Generated with Claude Code

jqnatividad and others added 3 commits October 25, 2026 09:16
`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant