Method: OcflTools::OcflValidator#verify_fixity
- Defined in:
- lib/ocfl_tools/ocfl_validator.rb
#verify_fixity(inventory_file: "#{@ocfl_object_root}/inventory.json", digest: 'md5') ⇒ OcflTools::OcflResults
Performs checksum validation of files listed in the inventory’s fixity block.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ocfl_tools/ocfl_validator.rb', line 64 def verify_fixity(inventory_file: "#{@ocfl_object_root}/inventory.json", digest: 'md5') # Gets the appropriate fixity block, calls compare_hash_checksums begin @inventory = load_inventory(inventory_file) rescue OcflTools::Errors::ValidationError @my_results.error('E210', 'verify_fixity', "Unable to process inventory file #{inventory_file}.") return @my_results end # Since fixity blocks are not required to be complete, we just validate what's there. # So get the fixity block, flip it, expand it, checksum it against the same files on disk. if @inventory.fixity.empty? @my_results.error('E111', "verify_fixity #{digest}", "No fixity block in #{inventory_file}!") return @my_results end unless @inventory.fixity.key?(digest) @my_results.error('E111', "verify_fixity #{digest}", "Requested algorithm #{digest} not found in fixity block.") return @my_results end fixity_checksums = OcflTools::Utils::Files.(@inventory.fixity[digest], @ocfl_object_root) my_files_on_disk = fixity_checksums.keys # Warn if there are less files in requested fixity block than in manifest. if @inventory.manifest.keys.size > fixity_checksums.keys.size missing_files = @inventory.manifest.keys.size - fixity_checksums.keys.size @my_results.warn( 'W111', "verify_fixity #{digest}", "#{missing_files} files in manifest are missing from fixity block." ) end # check these files exist on disk before trying to make checksums! my_files_on_disk.each do |file| unless File.file? file @my_results.error('E111', "verify_fixity #{digest}", "File #{file} in fixity block not found on disk.") my_files_on_disk.delete(file) end end disk_checksums = OcflTools::Utils::Files.create_digests(my_files_on_disk, digest) # And now we can compare values! OcflTools::Utils.compare_hash_checksums( disk_checksums: disk_checksums, inventory_checksums: fixity_checksums, results: @my_results, context: "verify_fixity #{digest}" ) end |