5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/dpn/bagit/ext/bagit/valid.rb', line 5
def consistent?
(manifest_files|tagmanifest_files).each do |mf|
readAlgo = /manifest-(.+).txt$/.match(File.basename(mf))[1]
algo = case readAlgo
when /sha1/i
Digest::SHA1
when /md5/i
Digest::MD5
when /sha256/i
Digest::SHA256
when /sha384/i
Digest::SHA384
when /sha512/i
Digest::SHA512
else
errors.add :consistency, "Algorithm #{readAlgo} is invalid or unsupported."
return false
end
File.open(mf) do |io|
io.each_line do |line|
expected, path = line.chomp.split(/\s+/, 2)
file = File.join(bag_dir, path)
if File.exist? file
actual = algo.file(file).hexdigest
if expected != actual
errors.add :consistency, "expected #{file} to have #{algo}: #{expected}, actual is #{actual}"
end
end
end
end
end
errors.on(:consistency).nil?
end
|