From c695055b4696b10fadb53f533eaa13361ce3b78c 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 4e4c655cf..0aed9040a 100644 --- a/lib/paperclip/storage/fog.rb +++ b/lib/paperclip/storage/fog.rb @@ -117,6 +117,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 79cc0f467..89479f3a5 100644 --- a/spec/paperclip/storage/fog_spec.rb +++ b/spec/paperclip/storage/fog_spec.rb @@ -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