Module: BagIt::Validity
- Included in:
- Bag
- Defined in:
- lib/bagit/valid.rb
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Return true if the manifest cover all files and all files are covered.
-
#consistent? ⇒ Boolean
Return true if all manifested files message digests match.
- #decode_filename(s) ⇒ Object
-
#valid_oxum? ⇒ Boolean
Checks for validity against Payload-Oxum.
Instance Method Details
#complete? ⇒ Boolean
Return true if the manifest cover all files and all files are covered.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bagit/valid.rb', line 23 def complete? logger = Logger.new(STDOUT) if manifest_files == [] errors.add :completeness, "there are no manifest files" end unmanifested_files.each do |file| logger.error("#{file} is present but not manifested".red) errors.add :completeness, "#{file} is present but not manifested" end empty_manifests.each do |file| logger.error("#{file} is manifested but not present".red) errors.add :completeness, "#{file} is manifested but not present" end tag_empty_manifests.each do |file| logger.error("#{file} is a manifested tag but not present".red) errors.add :completeness, "#{file} is a manifested tag but not present" end errors.on(:completeness).nil? end |
#consistent? ⇒ Boolean
Return true if all manifested files message digests match.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bagit/valid.rb', line 48 def consistent? (manifest_files|tagmanifest_files).each do |mf| # get the algorithm implementation File.basename(mf) =~ /manifest-(.+).txt$/ manifest_type = $1 algo = case manifest_type 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 raise ArgumentError.new("Algorithm #{manifest_type} is not supported.") end # Check every file in the manifest File.open(mf) do |io| io.each_line do |line| expected, path = line.chomp.split /\s+/, 2 file = File.join(bag_dir, decode_filename(path)) if File.exist? file actual = algo.file(file).hexdigest if expected.downcase != actual errors.add :consistency, "expected #{file} to have #{algo}: #{expected}, actual is #{actual}" end end end end end errors.on(:consistency).nil? end |
#decode_filename(s) ⇒ Object
15 16 17 18 19 |
# File 'lib/bagit/valid.rb', line 15 def decode_filename(s) s = s.gsub('%0D',"\r") s = s.gsub('%0A',"\n") return s end |
#valid_oxum? ⇒ Boolean
Checks for validity against Payload-Oxum
87 88 89 |
# File 'lib/bagit/valid.rb', line 87 def valid_oxum? bag_info["Payload-Oxum"] == payload_oxum end |