Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Rewind file in Storage::Fog if bucket does not exist
Browse files Browse the repository at this point in the history
There was a bug in the code where if you created a bucket the file would
get read but not rewind on the first pass through (when the bucket
didn't exist). So when we went into the retry logic the file would
already be read and zero bytes would get copied over from the file. This
fixes that by rewinding the file during the retry so it gets correctly
copied over the second time around.
  • Loading branch information
natesholland authored and sidraval committed Mar 9, 2018
1 parent 82b3114 commit c695055
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/paperclip/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def flush_writes
raise if retried
retried = true
directory.save
file.rewind
retry
ensure
file.rewind
Expand Down
5 changes: 5 additions & 0 deletions spec/paperclip/storage/fog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def custom_method
assert @dummy.save
assert @connection.directories.get(@fog_directory)
end

it "sucessfully rewinds the file during bucket creation" do
assert @dummy.save
expect(Paperclip.io_adapters.for(@dummy.avatar).read.length).to be > 0
end
end

context "with a bucket" do
Expand Down

0 comments on commit c695055

Please sign in to comment.