class Paperclip::Nginx::Upload::IOAdapter
Public Class Methods
default_options()
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 28 def self.default_options @default_options ||= { :tmp_path_whitelist => [], :move_tempfile => false } end
new(target, options = {})
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 20 def initialize(target, options = {}) @target = target @options = self.class.default_options.merge(options) require_whitelist_match!(@target[:tmp_path]) cache_current_values end
Private Instance Methods
cache_current_values()
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 53 def cache_current_values self.original_filename = @target[:original_name] @content_type = @target[:content_type].to_s.strip @size = File.size(@target[:tmp_path]) copy_or_move(@target[:tmp_path], destination.path) @tempfile = destination # Required to reopen the tempfile that we have overwritten @tempfile.open @tempfile.binmode end
copy_or_move(source_path, destination_path)
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 66 def copy_or_move(source_path, destination_path) if @options[:move_tempfile] FileUtils.mv(@target[:tmp_path], destination.path) else FileUtils.cp(@target[:tmp_path], destination.path) end end
matches_whitelist?(path)
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 43 def matches_whitelist?(path) tmp_path_whitelist.any? do |glob| File.fnmatch(glob, path) end end
require_whitelist_match!(path)
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 37 def require_whitelist_match!(path) unless matches_whitelist?(File.expand_path(path)) raise TmpPathNotInWhitelistError.new(path, tmp_path_whitelist) end end
tmp_path_whitelist()
click to toggle source
# File lib/paperclip/nginx/upload/io_adapter.rb, line 49 def tmp_path_whitelist @options[:tmp_path_whitelist] end