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
- #manifest_type(type) ⇒ 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bagit/valid.rb', line 22 def complete? logger = Logger.new(STDOUT) errors.add :completeness, "there are no manifest files" if manifest_files == [] 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bagit/valid.rb', line 62 def consistent? (manifest_files | tagmanifest_files).each do |mf| # get the algorithm implementation File.basename(mf) =~ /manifest-(.+).txt$/ type = Regexp.last_match(1) algo = manifest_type(type) # 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)) next unless File.exist? file actual = algo.file(file).hexdigest errors.add :consistency, "expected #{file} to have #{algo}: #{expected}, actual is #{actual}" if expected.downcase != actual end end end errors.on(:consistency).nil? end |
#decode_filename(s) ⇒ Object
14 15 16 17 18 |
# File 'lib/bagit/valid.rb', line 14 def decode_filename(s) s = s.gsub('%0D', "\r") s = s.gsub('%0A', "\n") s end |
#manifest_type(type) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bagit/valid.rb', line 44 def manifest_type(type) case 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, "Algorithm #{manifest_type} is not supported." end end |
#valid_oxum? ⇒ Boolean
Checks for validity against Payload-Oxum
85 86 87 |
# File 'lib/bagit/valid.rb', line 85 def valid_oxum? bag_info["Payload-Oxum"] == payload_oxum end |