diff --git a/lib/technoweenie/attachment_fu.rb b/lib/technoweenie/attachment_fu.rb index f833967..5c1e939 100644 --- a/lib/technoweenie/attachment_fu.rb +++ b/lib/technoweenie/attachment_fu.rb @@ -312,16 +312,14 @@ module Technoweenie # :nodoc: "#{rand Time.now.to_i}#{filename || 'attachment'}" end - @@filename_basename_regex = /^.*(\\|\/)/ - @@filename_character_regex = /[^\w\.\-]/ def sanitize_filename(filename) returning filename.strip do |name| # NOTE: File.basename doesn't work right with Windows paths on Unix # get only the filename, not the whole path - name.gsub! @@filename_basename_regex, '' + name.gsub! /^.*(\\|\/)/, '' # Finally, replace all non alphanumeric, underscore or periods with underscore - name.gsub! @@filename_character_regex, '_' + name.gsub! /[^\w\.\-]/, '_' end end diff --git a/lib/technoweenie/attachment_fu/backends/file_system_backend.rb b/lib/technoweenie/attachment_fu/backends/file_system_backend.rb index 843215c..3b7d8ad 100644 --- a/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +++ b/lib/technoweenie/attachment_fu/backends/file_system_backend.rb @@ -69,7 +69,8 @@ module Technoweenie # :nodoc: if save_attachment? # TODO: This overwrites the file if it exists, maybe have an allow_overwrite option? FileUtils.mkdir_p(File.dirname(full_filename)) - FileUtils.mv temp_path, full_filename + File.cp(temp_path, full_filename) + File.chmod(attachment_options[:chmod] || 0644, full_filename) end @old_filename = nil true