-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deduplicated filename not being persisted #2679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I ran our app CI with this commit and there are no failures (previously there was a bunch because of missing file error)
Thanks for fixing this! When can I except this to be released? |
Just released 3.0.2, which includes this fix. |
@mshibuya Thanks sir! That was fast 🚀 |
I still have the issue with 3.0.2. |
@mrudult I'm afraid that you may be missing something.
This is the problem itself. As described in the issue, if a user uploads two different files with the same filename results in one overwrites the other, ending up with only 1 file persisted. If you don't like the default deduplicated filenames, you can choose to override #deduplicated_filename with your own way like class YourUploader < CarrierWave::Uploader::Base
...
def deduplicated_filename
...
end
end |
@ps231402 Just saying so isn't very helpful. Please show me what you did and what you got, like a Rails console output. |
I'm sorry that the deduplication feature introduced in the 3.0 release is completely broken, as reported by #2677. This PR is another attempt to fix it.
The approach is to move the deduplication logic from #store! to
#write_identifier
, which is invoked on before_save thus allowing the modified filename(identifier) to be persisted. To work around the limitation that the deduplication timing can't be made earlier because#store_dir
relies on the model's id, the scope of deduplication was narrowed down only to filename, instead of whole#store_path
. This sometimes can lead to unnecessary deduplication in a case like a user decided to use a custom#store_dir
to handle deduplication by their own, but even if that happens it does not harm data consistency, so I think it's acceptable.@krasnoukhov I want your opinion on this, what do you think?