Commit a1b39cc6 by Jon Yurek

Reverted the nil assignment, as the issue in Rails/Rack was fixed. Also removed a lot of logging.

parent d75a5db7
...@@ -43,7 +43,7 @@ end ...@@ -43,7 +43,7 @@ end
# documentation for Paperclip::ClassMethods for more useful information. # documentation for Paperclip::ClassMethods for more useful information.
module Paperclip module Paperclip
VERSION = "2.2.7" VERSION = "2.2.8"
class << self class << self
# Provides configurability to Paperclip. There are a number of options available, such as: # Provides configurability to Paperclip. There are a number of options available, such as:
......
...@@ -49,8 +49,6 @@ module Paperclip ...@@ -49,8 +49,6 @@ module Paperclip
normalize_style_definition normalize_style_definition
initialize_storage initialize_storage
log("Paperclip attachment #{name} on #{instance.class} initialized.")
end end
# What gets called when you call instance.attachment = File. It clears # What gets called when you call instance.attachment = File. It clears
...@@ -62,9 +60,6 @@ module Paperclip ...@@ -62,9 +60,6 @@ module Paperclip
# If the file that is assigned is not valid, the processing (i.e. # If the file that is assigned is not valid, the processing (i.e.
# thumbnailing, etc) will NOT be run. # thumbnailing, etc) will NOT be run.
def assign uploaded_file def assign uploaded_file
# This is because of changes in Rails 2.3 that cause blank fields to send nil
return nil if uploaded_file.nil?
%w(file_name).each do |field| %w(file_name).each do |field|
unless @instance.class.column_names.include?("#{name}_#{field}") unless @instance.class.column_names.include?("#{name}_#{field}")
raise PaperclipError.new("#{@instance.class} model does not have required column '#{name}_#{field}'") raise PaperclipError.new("#{@instance.class} model does not have required column '#{name}_#{field}'")
...@@ -77,16 +72,12 @@ module Paperclip ...@@ -77,16 +72,12 @@ module Paperclip
end end
return nil unless valid_assignment?(uploaded_file) return nil unless valid_assignment?(uploaded_file)
log("Assigning #{uploaded_file.inspect} to #{name}")
uploaded_file.binmode if uploaded_file.respond_to? :binmode uploaded_file.binmode if uploaded_file.respond_to? :binmode
queue_existing_for_delete self.clear
@errors = {}
@validation_errors = nil
return nil if uploaded_file.nil? return nil if uploaded_file.nil?
log("Writing attributes for #{name}")
@queued_for_write[:original] = uploaded_file.to_tempfile @queued_for_write[:original] = uploaded_file.to_tempfile
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_')) instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_'))
instance_write(:content_type, uploaded_file.content_type.to_s.strip) instance_write(:content_type, uploaded_file.content_type.to_s.strip)
...@@ -149,13 +140,11 @@ module Paperclip ...@@ -149,13 +140,11 @@ module Paperclip
# the instance's errors and returns false, cancelling the save. # the instance's errors and returns false, cancelling the save.
def save def save
if valid? if valid?
log("Saving files for #{name}")
flush_deletes flush_deletes
flush_writes flush_writes
@dirty = false @dirty = false
true true
else else
log("Errors on #{name}. Not saving.")
flush_errors flush_errors
false false
end end
...@@ -293,7 +282,7 @@ module Paperclip ...@@ -293,7 +282,7 @@ module Paperclip
end end
def valid_assignment? file #:nodoc: def valid_assignment? file #:nodoc:
file.respond_to?(:original_filename) && file.respond_to?(:content_type) file.nil? || (file.respond_to?(:original_filename) && file.respond_to?(:content_type))
end end
def validate #:nodoc: def validate #:nodoc:
...@@ -370,12 +359,10 @@ module Paperclip ...@@ -370,12 +359,10 @@ module Paperclip
end end
def post_process_styles def post_process_styles
log("Post-processing #{name}")
@styles.each do |name, args| @styles.each do |name, args|
begin begin
raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank? raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
@queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor| @queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
log("Processing #{name} #{file} in the #{processor} processor.")
Paperclip.processor(processor).make(file, args, self) Paperclip.processor(processor).make(file, args, self)
end end
rescue PaperclipError => e rescue PaperclipError => e
...@@ -397,7 +384,6 @@ module Paperclip ...@@ -397,7 +384,6 @@ module Paperclip
def queue_existing_for_delete #:nodoc: def queue_existing_for_delete #:nodoc:
return unless file? return unless file?
log("Queueing the existing files for #{name} for deletion.")
@queued_for_delete += [:original, *@styles.keys].uniq.map do |style| @queued_for_delete += [:original, *@styles.keys].uniq.map do |style|
path(style) if exists?(style) path(style) if exists?(style)
end.compact end.compact
......
...@@ -36,11 +36,10 @@ module Paperclip ...@@ -36,11 +36,10 @@ module Paperclip
alias_method :to_io, :to_file alias_method :to_io, :to_file
def flush_writes #:nodoc: def flush_writes #:nodoc:
logger.info("[paperclip] Writing files for #{name}")
@queued_for_write.each do |style, file| @queued_for_write.each do |style, file|
file.close file.close
FileUtils.mkdir_p(File.dirname(path(style))) FileUtils.mkdir_p(File.dirname(path(style)))
logger.info("[paperclip] -> #{path(style)}") logger.info("[paperclip] saving #{path(style)}")
FileUtils.mv(file.path, path(style)) FileUtils.mv(file.path, path(style))
FileUtils.chmod(0644, path(style)) FileUtils.chmod(0644, path(style))
end end
...@@ -48,10 +47,9 @@ module Paperclip ...@@ -48,10 +47,9 @@ module Paperclip
end end
def flush_deletes #:nodoc: def flush_deletes #:nodoc:
logger.info("[paperclip] Deleting files for #{name}")
@queued_for_delete.each do |path| @queued_for_delete.each do |path|
begin begin
logger.info("[paperclip] -> #{path}") logger.info("[paperclip] deleting #{path}")
FileUtils.rm(path) if File.exist?(path) FileUtils.rm(path) if File.exist?(path)
rescue Errno::ENOENT => e rescue Errno::ENOENT => e
# ignore file-not-found, let everything else pass # ignore file-not-found, let everything else pass
...@@ -151,7 +149,6 @@ module Paperclip ...@@ -151,7 +149,6 @@ module Paperclip
base.class.interpolations[:s3_domain_url] = lambda do |attachment, style| base.class.interpolations[:s3_domain_url] = lambda do |attachment, style|
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}" "#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
end end
ActiveRecord::Base.logger.info("[paperclip] S3 Storage Initalized.")
end end
def s3 def s3
...@@ -193,10 +190,9 @@ module Paperclip ...@@ -193,10 +190,9 @@ module Paperclip
alias_method :to_io, :to_file alias_method :to_io, :to_file
def flush_writes #:nodoc: def flush_writes #:nodoc:
logger.info("[paperclip] Writing files for #{name}")
@queued_for_write.each do |style, file| @queued_for_write.each do |style, file|
begin begin
logger.info("[paperclip] -> #{path(style)}") logger.info("[paperclip] saving #{path(style)}")
key = s3_bucket.key(path(style)) key = s3_bucket.key(path(style))
key.data = file key.data = file
key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)}.merge(@s3_headers)) key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)}.merge(@s3_headers))
...@@ -208,10 +204,9 @@ module Paperclip ...@@ -208,10 +204,9 @@ module Paperclip
end end
def flush_deletes #:nodoc: def flush_deletes #:nodoc:
logger.info("[paperclip] Writing files for #{name}")
@queued_for_delete.each do |path| @queued_for_delete.each do |path|
begin begin
logger.info("[paperclip] -> #{path}") logger.info("[paperclip] deleting #{path}")
if file = s3_bucket.key(path) if file = s3_bucket.key(path)
file.delete file.delete
end end
......
...@@ -599,14 +599,14 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -599,14 +599,14 @@ class AttachmentTest < Test::Unit::TestCase
end end
end end
should "not delete the files saving in a deprecated manner" do should "delete the files after assigning nil" do
@attachment.expects(:instance_write).with(:file_name, nil).never @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil).never @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil).never @attachment.expects(:instance_write).with(:file_size, nil)
@attachment.expects(:instance_write).with(:updated_at, nil).never @attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.assign nil @attachment.assign nil
@attachment.save @attachment.save
@existing_names.each{|f| assert File.exists?(f) } @existing_names.each{|f| assert ! File.exists?(f) }
end end
should "delete the files when you call #clear and #save" do should "delete the files when you call #clear and #save" do
......
...@@ -91,8 +91,6 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -91,8 +91,6 @@ class PaperclipTest < Test::Unit::TestCase
end end
should "not assign the avatar on mass-set" do should "not assign the avatar on mass-set" do
@dummy.logger.expects(:debug)
@dummy.attributes = { :other => "I'm set!", @dummy.attributes = { :other => "I'm set!",
:avatar => @file } :avatar => @file }
...@@ -101,8 +99,6 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -101,8 +99,6 @@ class PaperclipTest < Test::Unit::TestCase
end end
should "still allow assigment on normal set" do should "still allow assigment on normal set" do
@dummy.logger.expects(:debug).times(0)
@dummy.other = "I'm set!" @dummy.other = "I'm set!"
@dummy.avatar = @file @dummy.avatar = @file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment