Skip to content

feat: add --rename flag to auto-rename on conflict - #1088

Open
GhostCoder6969 wants to merge 4 commits into
ouch-org:mainfrom
GhostCoder6969:auto-rename-conflicts-901
Open

GhostCoder6969 wants to merge 4 commits into
ouch-org:mainfrom
GhostCoder6969:auto-rename-conflicts-901

Conversation

@GhostCoder6969

Copy link
Copy Markdown

Closes #901. There is now a global --rename flag that answers every file conflict with the rename option, so scripts stop prompting for input. It conflicts with --yes and --no, and the --help snapshots are updated. I verified the flag end to end with a new integration test plus the full suite with --no-default-features (this box has no libclang for the default build, CI will cover that). Happy to rename the flag if you prefer something else.

Adds a global --rename flag that resolves file conflicts by renaming without prompting, instead of answering them with --yes/--no or typing r each time. Closes ouch-org#901.
@valoq

valoq commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

This command now crashes ouch:
ouch --rename d --yes archive.tar.gz

With the --here option, --rename does not handle all conflicts. It throws an error when a symlink, hard link or folder in the archive has the same name as an existing file or a file has the same name as an existing folder

--rename also says yes to the other questions ouch asks, not only to conflicts

--rename plus --yes errored out cleanly instead of panicking,
other questions ask again instead of copying --yes, and
symlink, hardlink and dir entries rename aside on conflict.
@GhostCoder6969

GhostCoder6969 commented Sep 27, 2026 •

Copy link
Copy Markdown
Author

Good catches, all three are fixed now.

The --rename plus --yes crash was real, my bad. Clap only caught that clash when both flags came before the subcommand, so it slipped through and hit an unreachable. It errors out cleanly now.

--rename no longer says yes to the other questions, that was wrong of me. It only covers file conflicts and everything else asks like normal.

And the --here clashes work now. Symlinks, hardlinks and files landing on each other rename aside, and when a directory lands on an existing file the file moves aside so the archive layout stays intact. I tried each case by hand plus three new tests, full suite green.

@valoq

valoq commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

There are a few more issues left:

  • cargo +nightly fmt --check fails because of src/archive/zip.rs
  • ouch --yes d --no file.tar.gz shows the new error "Cannot combine --rename with --yes or --no"
  • With --rename, other questions like the one about an unknown extension can no longer be answered
  • When a tar archive folder x has the same name as an existing file x, the user file is renamed to x_1

…rs aside

--yes plus --no without --rename no longer reports the rename error,
it gets its own message now. The rename error only fires when --rename
is actually passed.

Non-conflict questions (unknown extension and the like) still prompt
under --rename, covered by tests answering yes and no.

A tar or zip directory landing on an existing file renames the incoming
entry aside now, the user's file stays untouched, and entries below the
renamed directory follow it. Matches the --rename help text.
@GhostCoder6969

Copy link
Copy Markdown
Author

All four fixed, I think thats all four.

The fmt failure was just my import wrapping in zip.rs, I ran cargo fmt and it is clean now.

The --yes plus --no thing was my catch all arm firing the rename error even when --rename was never passed. I split the checks so the rename error only fires when --rename is actually there, and --yes with --no gets its own message now.

The unknown extension question already asks again after my last push, I checked it by hand piping y and n in. I added two tests so it stays that way, one answers yes and extracts, the other answers no and nothing gets written.

The tar folder case was backwards, you were right. I moved the user file aside before and now the incoming directory goes to x_1 instead, with everything below it following along. Zip got the same treatment since it errored out there. This matches the flag help text too, it says the output gets renamed.

Full suite green on my end plus the fmt check.

A 7z directory landing on an existing file errored out instead of
renaming aside like tar and zip do. 7z lists files before their
parent dirs, so entries below a blocked path move the topmost
blocking ancestor aside first and follow it. Covered by a test
mirroring the tar and zip cases.
@GhostCoder6969

Copy link
Copy Markdown
Author

I went through every item again on the current branch. The fmt check is clean, the yes plus no clash gets its own error now, the format sniffing question still asks under rename, tar puts the incoming folder aside and keeps your file, and the rename plus yes combos error out cleanly in every flag order. The one real gap I found was 7z, a folder landing on a file errored out there, so I gave it the same treatment as tar and zip and added a test for it. Full suite is green on my end.

@valoq

valoq commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator
  • a dangling symlink now counts as a free name and extraction writes to the link target
  • --rename refuses --yes, so questions other than file conflicts still prompt and scripts cannot answer them

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.

[Feature Request] Add cli option to rename conflicting output dir

2 participants