From 93c04f2666b60af890a7431bec802b7d00e29b34 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 2 Dec 2008 17:57:13 +0000 Subject: Fixed: wrong digest for text files under Windows (#2264). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2085 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f838076c6..3bcc266bc 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -72,7 +72,7 @@ class Attachment < ActiveRecord::Base File.open(diskfile, "wb") do |f| f.write(@temp_file.read) end - self.digest = Digest::MD5.hexdigest(File.read(diskfile)) + self.digest = self.class.digest(diskfile) end # Don't save the content type if it's longer than the authorized length if self.content_type && self.content_type.length > 255 @@ -133,4 +133,11 @@ private end df end + + # Returns the MD5 digest of the file at given path + def self.digest(filename) + File.open(filename, 'rb') do |f| + Digest::MD5.hexdigest(f.read) + end + end end -- cgit v1.2.3