From 6282012eca6f14c3b0b943ee52eba9a3a590e675 Mon Sep 17 00:00:00 2001 From: Dimitris Bliablias Date: Wed, 17 Dec 2014 12:11:29 +0200 Subject: [PATCH 1/5] Fog storage handles missing files on delete ... to mirror the file storage behaviour. --- lib/carrierwave/storage/fog.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index f016b14d1..03fd1503b 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -185,6 +185,7 @@ def content_type=(new_content_type) def delete # avoid a get by just using local reference directory.files.new(:key => path).destroy + rescue ::Fog::Service::NotFound end ## From 567026fb915c88143e62202a9dd7385dd4d7389f Mon Sep 17 00:00:00 2001 From: Andreas Loupasakis Date: Tue, 3 Feb 2015 14:28:56 +0200 Subject: [PATCH 2/5] Bump version to 0.10.0.skroutz --- lib/carrierwave/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index b3b013d70..383c053a3 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "0.10.0" + VERSION = "0.10.0.skroutz" end From a8b75f185b86ec668876c86a16d060ae5828ae88 Mon Sep 17 00:00:00 2001 From: Thalis Kapros Date: Thu, 12 Feb 2015 16:47:24 +0200 Subject: [PATCH 3/5] Add callback to invalidate memoized filename after save --- lib/carrierwave/orm/activerecord.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/carrierwave/orm/activerecord.rb b/lib/carrierwave/orm/activerecord.rb index c83da01cb..b2cc04f99 100644 --- a/lib/carrierwave/orm/activerecord.rb +++ b/lib/carrierwave/orm/activerecord.rb @@ -31,6 +31,7 @@ def mount_uploader(column, uploader=nil, options={}, &block) after_commit :"mark_remove_#{column}_false", :on => :update before_update :"store_previous_model_for_#{column}" after_save :"remove_previously_stored_#{column}" + after_save :"invalidate_memoized_filename_for_#{column}" class_eval <<-RUBY, __FILE__, __LINE__+1 def #{column}=(new_file) @@ -51,6 +52,10 @@ def remove_#{column}! _mounter(:#{column}).write_identifier end + def invalidate_memoized_filename_for_#{column} + send(:instance_variable_set, :"@#{column}_regularized_filename", nil) + end + def serializable_hash(options=nil) hash = {} From 84e9e834cb245bce9fbe8cd4cf6431de120ccaa8 Mon Sep 17 00:00:00 2001 From: Thalis Kapros Date: Thu, 12 Feb 2015 17:54:42 +0200 Subject: [PATCH 4/5] Bump version to 0.10.0.1.skroutz --- lib/carrierwave/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/version.rb b/lib/carrierwave/version.rb index 383c053a3..7535f048f 100644 --- a/lib/carrierwave/version.rb +++ b/lib/carrierwave/version.rb @@ -1,3 +1,3 @@ module CarrierWave - VERSION = "0.10.0.skroutz" + VERSION = "0.10.0.1.skroutz" end From ff62cacec1a1db4e1aaf1f41c348d29884e3c59e Mon Sep 17 00:00:00 2001 From: Aggelos Avgerinos Date: Mon, 16 Feb 2015 21:31:07 +0200 Subject: [PATCH 5/5] Fog storage handles missing files on size --- lib/carrierwave/storage/fog.rb | 2 +- spec/storage/fog_helper.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 03fd1503b..0520b60c4 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -237,7 +237,7 @@ def read # [Integer] size of file body # def size - file.content_length + file.nil? ? 0 : file.content_length end ## diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index abfbd40a2..173d35d18 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -175,6 +175,18 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base @fog_file.delete @directory.files.head(store_path).should == nil end + + context "when the files has been deleted" do + before do + @fog_file.delete + end + + it "does not blow up" do + expect { + @fog_file.size + }.not_to raise_error + end + end end describe '#retrieve!' do