From 958d95b2e4ffb94a901184ad0df54b5d5df01fd8 Mon Sep 17 00:00:00 2001 From: Nate Holland Date: Thu, 8 Mar 2018 08:29:36 -0600 Subject: [PATCH] Rewind file in Storage::Fog if bucket does not exist 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. --- lib/paperclip/storage/fog.rb | 1 + spec/paperclip/storage/fog_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/paperclip/storage/fog.rb b/lib/paperclip/storage/fog.rb index 8d0ed16a0..34650e490 100644 --- a/lib/paperclip/storage/fog.rb +++ b/lib/paperclip/storage/fog.rb @@ -114,6 +114,7 @@ def flush_writes raise if retried retried = true directory.save + file.rewind retry ensure file.rewind diff --git a/spec/paperclip/storage/fog_spec.rb b/spec/paperclip/storage/fog_spec.rb index a48db202e..e0c1d027a 100644 --- a/spec/paperclip/storage/fog_spec.rb +++ b/spec/paperclip/storage/fog_spec.rb @@ -199,6 +199,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