From 725e1683ca043c032caece5b584d28e36f8044c7 Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Tue, 27 Nov 2018 17:26:19 +0300 Subject: [PATCH] Store styles in queued_for_delete --- lib/paperclip/attachment.rb | 7 ++++--- lib/paperclip/storage/delayeds3.rb | 5 +++-- lib/paperclip/storage/filesystem.rb | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index fea3214..fb9afbb 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -43,7 +43,8 @@ module Paperclip attr_reader :attachment_name, :options, :validations # Extracted from options - attr_reader :url_template, :path_template, :default_url, :processing_url, :styles, :default_style, :whiny + attr_reader :url_template, :path_template, :default_url, :processing_url, + :styles, :all_styles, :default_style, :whiny def setup(name, options) @attachment_name = name @@ -54,6 +55,7 @@ module Paperclip @default_url = options[:default_url] @processing_url = options[:processing_url] || default_url @styles = StylesParser.new(options).styles + @all_styles = [:original, *styles.keys].uniq @default_style = options[:default_style] @whiny = options[:whiny_thumbnails] || options[:whiny] end @@ -412,8 +414,7 @@ module Paperclip def queue_existing_for_delete #:nodoc: return unless file? - all_styles = [:original, *styles.keys] - queued_for_delete.concat(all_styles.uniq.map { |style| filesystem_path(style) }.compact) + queued_for_delete.concat(self.class.all_styles) end def flush_errors #:nodoc: diff --git a/lib/paperclip/storage/delayeds3.rb b/lib/paperclip/storage/delayeds3.rb index 0f41e97..6ceeec0 100644 --- a/lib/paperclip/storage/delayeds3.rb +++ b/lib/paperclip/storage/delayeds3.rb @@ -163,7 +163,7 @@ module Paperclip def filesystem_paths h = {} - [:original, *styles.keys].uniq.map do |style| + self.class.all_styles.uniq.map do |style| path = filesystem_path(style) h[style] = path if File.exist?(path) end @@ -271,7 +271,8 @@ module Paperclip return end - queued_for_delete.each do |path| + queued_for_delete.each do |style| + path = filesystem_path(style) log("Deleting local file #{path}") delete_recursive(path) end diff --git a/lib/paperclip/storage/filesystem.rb b/lib/paperclip/storage/filesystem.rb index a99d6d5..4a95e2a 100644 --- a/lib/paperclip/storage/filesystem.rb +++ b/lib/paperclip/storage/filesystem.rb @@ -44,7 +44,8 @@ module Paperclip end def flush_deletes #:nodoc: - queued_for_delete.each do |path| + queued_for_delete.each do |style| + path = self.path(style) begin log("deleting #{path}") FileUtils.rm(path)