Fixed: attachments with the same name at the same time overwrite (#3691).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3511 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2010-02-28 11:12:40 +00:00
parent 82310d3162
commit 241f79ac06
2 changed files with 19 additions and 5 deletions
+9 -5
View File
@@ -147,14 +147,18 @@ private
# Returns an ASCII or hashed filename
def self.disk_filename(filename)
df = DateTime.now.strftime("%y%m%d%H%M%S") + "_"
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
ascii = ''
if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
df << filename
ascii = filename
else
df << Digest::MD5.hexdigest(filename)
ascii = Digest::MD5.hexdigest(filename)
# keep the extension if any
df << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
end
df
while File.exist?(File.join(@@storage_path, "#{timestamp}_#{ascii}"))
timestamp.succ!
end
"#{timestamp}_#{ascii}"
end
end