Module: BagIt::Validity

Included in:
Bag
Defined in:
lib/bagit/valid.rb

Instance Method Summary collapse

Instance Method Details

#complete?Boolean

Return true if the manifest cover all files and all files are covered.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bagit/valid.rb', line 15

def complete?

  unmanifested_files.each do |file|
    errors.add :completeness, "#{file} is present but not manifested"
  end

  empty_manifests.each do |file|
    errors.add :completeness, "#{file} is manifested but not present"
  end
  tag_empty_manifests.each do |file|
    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.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bagit/valid.rb', line 32

def consistent?
  (manifest_files|tagmanifest_files).each do |mf|
    # get the algorithm implementation
    File.basename(mf) =~ /manifest-(.+).txt$/
    algo = case $1
           when /sha1/i
             Digest::SHA1
           when /md5/i
             Digest::MD5
           else
             :unknown
           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, 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

#valid_oxum?Boolean

Checks for validity against Payload-Oxum

Returns:

  • (Boolean)


64
65
66
# File 'lib/bagit/valid.rb', line 64

def valid_oxum?
  bag_info["Payload-Oxum"] == payload_oxum
end