Skip to content

new flag: Enable renaming during file upload if duplicate exists#1453

Merged
svenstaro merged 2 commits intosvenstaro:masterfrom
Atreyagaurav:master
Jun 27, 2025
Merged

new flag: Enable renaming during file upload if duplicate exists#1453
svenstaro merged 2 commits intosvenstaro:masterfrom
Atreyagaurav:master

Conversation

@Atreyagaurav
Copy link
Copy Markdown
Contributor

Fixes #1452

I think this will work as a flag to rename files. It won't work when the file contains multiple extension like .tar.gz which is hard to do, as we could make it work with that, but any file with multiple . in the text for no meaning will mess it up. But I can make that change if you think that's acceptable.

Also, it will break compatibility, but we could combine the overwrite and rename flags into a single flag like --duplicate-files that takes enum (rename/overwrite).

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

I also thought about just renaming when overwrite is false instead of error. Which is probably a reasonable thing to do as well. Let me know what you think.

@svenstaro
Copy link
Copy Markdown
Owner

svenstaro commented Sep 21, 2024

Thanks for this! I'd really like to see some tests here, though. It just occurred to me that we have no tests for conflicting files without any flags set nor did we have one for --overwrite-files. Would be up for making a bunch of tests showing

  1. Overwriting files is not possible without extra flags
  2. --overwrite-files works as expected
  3. --rename-duplicate works as expected
    ?

I also thought about just renaming when overwrite is false instead of error. Which is probably a reasonable thing to do as well. Let me know what you think.

I think we want an error here by default. It's safer.

Also, it will break compatibility, but we could combine the overwrite and rename flags into a single flag like --duplicate-files that takes enum (rename/overwrite).

I do like the enum idea. I'm fine breaking compatibility here. We have to make sure it's well pointed out in the CHANGELOG so people can quickly spot it.

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

Thanks for the review, I'll push with the tests once I have a bit more free time.

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

I have added the tests for the three conditions mentioned previously.

I copied the tests from the upload_file test, and modified them. The test are for failing to upload a duplicate file, checking overwrite with new contents, and checking rename flag that creates an additional file.

@svenstaro
Copy link
Copy Markdown
Owner

@Atreyagaurav Looking great! What do you think about the enum thing that we discussed above?

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

Atreyagaurav commented Sep 23, 2024

I added it as enum, and made the default be error. So only breaking change is
-o needs a value as it is no longer bool. and --overwrite-files is not available. I named the new flag on-duplicate-files

I have the tests updated as well. And I also manually tested.

@svenstaro
Copy link
Copy Markdown
Owner

Hey, I'd like to get this into the next release if possible. Could you rebase this and then it should be good to merge?

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

Hi, it looks like a lot of things were changed while doing the multipart file upload. Would have been nice to merge it before that. I'll have to look into the conflicts a little more deeply and understand the new process as well, do you think you can wait like a week for it?

@svenstaro
Copy link
Copy Markdown
Owner

Hi, it looks like a lot of things were changed while doing the multipart file upload. Would have been nice to merge it before that. I'll have to look into the conflicts a little more deeply and understand the new process as well, do you think you can wait like a week for it?

Yeah, sorry about that. Life happened. Anyway, I can certainly wait a week. :)

@svenstaro
Copy link
Copy Markdown
Owner

Hey, @Atreyagaurav, do you think we can push this over the finish line soon?

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

Since there were conflicts and other changes in master, I just redid everything on the new master and force-pushed. Should be fine. For the tests, I took the examples from other tests in the tests/file_upload.rs to make a file in the function itself, instead of using the fixtures. Might be better to redo all of them in a separate issue.

Copy link
Copy Markdown
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're super close now. Sorry for taking some time to re-review this.

@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

The clippy error has a lot of problems from other codes besides the one I changed as well.

We could use #[allow(clippy::uninlined_format_args)] for now, or change those. What do you think?

I didn't get the error locally, so there's probably changes in clippy for this to be an error now.

@svenstaro
Copy link
Copy Markdown
Owner

Please rebase, I made clippy happy on master!

@svenstaro svenstaro closed this Jun 27, 2025
@svenstaro svenstaro reopened this Jun 27, 2025
@svenstaro
Copy link
Copy Markdown
Owner

Whoops.

@svenstaro svenstaro merged commit 7360fff into svenstaro:master Jun 27, 2025
28 of 34 checks passed
@svenstaro
Copy link
Copy Markdown
Owner

Thanks! I'll merge this as is.

svenstaro added a commit that referenced this pull request Jun 27, 2025
@Atreyagaurav
Copy link
Copy Markdown
Contributor Author

Thank you!

Sorry I was in a meeting and couldn't rebase.

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.

No rename option, only overwrite

2 participants