* finished Issue 111: Garbled filenames on dmsf file forder in server side

git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@204 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
vit.jonas@gmail.com 2011-07-15 13:45:06 +00:00
parent ccc732aff2
commit b36990bb8a
5 changed files with 14 additions and 4 deletions

View File

@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require "tmpdir" require "tmpdir"
require "digest/md5"
module DmsfHelper module DmsfHelper
@ -37,8 +38,16 @@ module DmsfHelper
# get only the filename, not the whole path # get only the filename, not the whole path
just_filename = File.basename(filename.gsub('\\\\', '/')) just_filename = File.basename(filename.gsub('\\\\', '/'))
# Finally, replace all non alphanumeric, hyphens or periods with underscore # replace all non alphanumeric, hyphens or periods with underscore
just_filename.gsub(/[^\w\.\-]/,'_') just_filename = just_filename.gsub(/[^\w\.\-]/,'_')
unless just_filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
# keep the extension if any
extension = $1 if just_filename =~ %r{(\.[a-zA-Z0-9]+)$}
just_filename = Digest::MD5.hexdigest(just_filename) << extension
end
just_filename
end end
def self.filetype_css(filename) def self.filetype_css(filename)

View File

@ -188,12 +188,13 @@ class DmsfFileRevision < ActiveRecord::Base
end end
def new_storage_filename def new_storage_filename
raise DmsfAccessError, "File id is not set" unless self.file.id
filename = DmsfHelper.sanitize_filename(self.name) filename = DmsfHelper.sanitize_filename(self.name)
timestamp = DateTime.now.strftime("%y%m%d%H%M%S") timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.id}_#{filename}")) while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.file.id}_#{filename}"))
timestamp.succ! timestamp.succ!
end end
"#{timestamp}_#{file.id}_#{filename}" "#{timestamp}_#{self.file.id}_#{filename}"
end end
def copy_file_content(open_file) def copy_file_content(open_file)