diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 78347127..580d02b8 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -603,16 +603,6 @@ module RedmineDmsf if new_revision.save new_revision.copy_file_content request.body - # Digest - sha = Digest::SHA256.new - if request.body.respond_to?(:read) - while (buffer = request.body.read(8192)) - sha.update buffer - end - else - sha.update request.body - end - new_revision.digest = sha.hexdigest new_revision.save # Notifications DmsfMailer.deliver_files_updated project, [f] diff --git a/lib/tasks/dmsf_create_digests.rake b/lib/tasks/dmsf_create_digests.rake index 8b30e416..644ba687 100644 --- a/lib/tasks/dmsf_create_digests.rake +++ b/lib/tasks/dmsf_create_digests.rake @@ -48,7 +48,9 @@ class DmsfCreateDigest end def dmsf_create_digests - revisions = DmsfFileRevision.where(['digest IS NULL OR length(digest) < ?', @force_sha256 ? 64 : 32]) + revisions = DmsfFileRevision.where(['digest IS NULL OR digest = ? OR length(digest) < ?', + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', # Wrong version when uploading a document via WebDAV #1385 + @force_sha256 ? 64 : 32]) count = revisions.count n = 0 revisions.each_with_index do |rev, i| diff --git a/test/integration/webdav/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb index c6b26eee..78ec97ff 100644 --- a/test/integration/webdav/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -338,5 +338,16 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest assert_response :unprocessable_entity end end + + def test_put_digest + assert_difference '@file1.dmsf_file_revisions.count', +1 do + put "/dmsf/webdav/#{@project1.identifier}/#{@file1.name}", params: '1234', + headers: @jsmith.merge!({ content_type: :text }) + assert_response :created + end + @file1.last_revision.reload + sha = Digest::SHA256.file(@file1.last_revision.disk_file) + assert_equal sha, @file1.last_revision.digest + end end \ No newline at end of file