Project

General

Profile

Patch #25240 » 0002-adds-a-rake-task-to-convert-the-digests-of-existing-.patch

Jens Krämer, 2017-03-02 04:27

View differences:

app/models/attachment.rb
end
end
# Updates attachments' digests to SHA256
def self.update_digest_to_sha256
Attachment.where("length(digest) < 64").find_in_batches do |group|
group.each do |attachment|
attachment.update_digest_to_sha256!
end
end
end
def update_digest_to_sha256!
sha = Digest::SHA256.new
File.open(diskfile, 'rb') do |f|
while buffer = f.read(8192)
sha.update(buffer)
end
end
update_column :digest, sha.hexdigest
end
# Returns true if the extension is allowed regarding allowed/denied
# extensions defined in application settings, otherwise false
def self.valid_extension?(extension)
lib/tasks/redmine.rake
task :move_to_subdirectories => :environment do
Attachment.move_from_root_to_target_directory
end
desc 'Updates attachment digests to SHA256'
task :update_digest_to_sha256 => :environment do
Attachment.update_digest_to_sha256
end
end
namespace :tokens do
test/unit/attachment_test.rb
assert_equal 'text/plain', attachment.content_type
end
test 'should update digest to sha256' do
set_fixtures_attachments_directory
attachment = Attachment.find 4
assert File.readable? attachment.diskfile
attachment.update_digest_to_sha256!
assert_equal 'c2db49ac68eaebb1703db09411dcd8186b395f4ae8482e449a5d5abff96c7fb2', attachment.digest
end
def test_update_attachments
attachments = Attachment.where(:id => [2, 3]).to_a
......
else
puts '(ImageMagick convert not available)'
end
end
(1-1/6)