mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Story#119627029 - extract checksum calculator
(cherry picked from commit c90c985
)
This commit is contained in:
parent
2e4e07503f
commit
ca74eaeca1
2 changed files with 8 additions and 4 deletions
|
@ -55,6 +55,12 @@ class LegalDocument < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def calc_checksum
|
||||
digest = Digest::SHA1.new
|
||||
digest.update File.binread(path)
|
||||
digest.to_s
|
||||
end
|
||||
|
||||
def add_creator
|
||||
self.creator_str = ::PaperTrail.whodunnit
|
||||
true
|
||||
|
|
|
@ -14,9 +14,7 @@ namespace :legal_doc do
|
|||
|
||||
LegalDocument.where(checksum: [nil, ""]).find_each do |x|
|
||||
if File.exist?(x.path)
|
||||
digest = Digest::SHA1.new
|
||||
digest.update File.binread(x.path)
|
||||
x.checksum = digest.to_s
|
||||
x.checksum = x.calc_checksum
|
||||
x.save
|
||||
count += 1
|
||||
end
|
||||
|
@ -33,7 +31,7 @@ namespace :legal_doc do
|
|||
count = 0
|
||||
modified = Array.new
|
||||
|
||||
LegalDocument.find_each do |x|
|
||||
LegalDocument.where.not(checksum: [nil, ""]).find_each do |x|
|
||||
if File.exist?(x.path)
|
||||
|
||||
LegalDocument.where(checksum: x.checksum) do |y|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue