Skip to content
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

Deduplication Disassociates ActiveRecord Filename from Underlying Storage #2678

Closed
DBugger32 opened this issue Jul 26, 2023 · 2 comments
Closed
Labels

Comments

@DBugger32
Copy link

DBugger32 commented Jul 26, 2023

Was hoping this was fixed with 3.0.1, but it still occurs. When updating an uploader with the same file, the underlying stored filename is deduplicated, but the active_record filename stays the same. This is the minimal example....

 mount_uploader :signed_electronic_document, OldReleaseUploader, mount_on: :signed_electronic_document_filename
doc =  File.open(File.expand_path('../../fixtures/files/Example Annotated Document.pdf', __FILE__))
r = Release.create!
r.signed_electronic_document = doc
r.save!

puts "After Initial Save -----------"
puts "url     : #{r.signed_electronic_document.url}"
puts "ar name : #{r.signed_electronic_document_filename}"
puts "store_dir files"
puts Dir["/home/app/myapp/private/#{r.signed_electronic_document.store_dir}/*.pdf"]
puts ""
#update with same document
r.assign_attributes(verified: true, signed_electronic_document: doc)
r.save!
puts "After Second Save -----------"
puts "url     : #{r.signed_electronic_document.url}"
puts "ar name : #{r.signed_electronic_document_filename}"
puts "store_dir files"
puts Dir["/home/app/myapp/private/#{r.signed_electronic_document.store_dir}/*.pdf"]

This is the output...

After Initial Save -----------
url     : /uploads/release/signed_document/980191116/Example_Annotated_Document.pdf
ar name : Example_Annotated_Document.pdf
store_dir files
/home/app/myapp/private/uploads/release/signed_document/980191116/Example_Annotated_Document.pdf

After Second Save -----------
url     : /uploads/release/signed_document/980191116/Example_Annotated_Document(2).pdf
ar name : Example_Annotated_Document.pdf
store_dir files
/home/app/myapp/private/uploads/release/signed_document/980191116/Example_Annotated_Document(2).pdf

And sure enough, if you try to load the object and read the file

r.reload
r.signed_electronic_document.read

you receive...

Errno::ENOENT: No such file or directory @ rb_sysopen - /home/app/myapp/private/uploads/release/signed_document/980191116/Example_Annotated_Document.pdf

Expect that the active_record filename and underlying storage should remain synched

PS. A config setting to toggle off/on carrierwave's deduplication efforts would be useful

@mshibuya
Copy link
Member

Sorry I overlooked this. This was already reported as a PR by #2677, and #2679 is my proposal to fix.

@mshibuya
Copy link
Member

mshibuya commented Aug 1, 2023

Fixed in 3.0.2.

@mshibuya mshibuya closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants