Class: Ki::VersionTester
Overview
Tests that a version is intact. Version can be in repository or as file. Checks that all files have correct hashes. If recursive is set to true, goes through all dependencies
Instance Method Summary collapse
-
#test_version(root_version, &block) ⇒ bool
Tests that a version is intact * test_version(version) expects a Version parameter.
- #verify_hash(file_hash, full_path, possible_hashes) ⇒ Object
Instance Method Details
#test_version(root_version, &block) ⇒ bool
Tests that a version is intact
-
test_version(version) expects a Version parameter
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 62 63 64 65 66 67 68 |
# File 'lib/data_access/version_helpers.rb', line 33 def test_version(root_version, &block) all_ok = true possible_hashes = KiCommand::KiExtensions.find!("/hashing") # iterates through all versions root_version.version_iterator.iterate_versions do |v| binaries = v.binaries = v. .cached_data .files.each do |file_hash| file_path = file_hash["path"] full_path = binaries.path(file_path) issue = nil if !File.exists?(full_path) issue="missing" elsif File.size(full_path) != file_hash["size"] issue="wrong size" elsif !verify_hash(file_hash, full_path, possible_hashes) issue="wrong hash" end if issue all_ok = false (results[issue]||=[]) << [v, file_path] if block block.call(issue, v, file_path) end if print puts "#{v..path}: '#{file_path}' #{issue} '#{v.binaries.path(file_path)}'" end end end if !recursive break end end all_ok end |
#verify_hash(file_hash, full_path, possible_hashes) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/data_access/version_helpers.rb', line 70 def verify_hash(file_hash, full_path, possible_hashes) file_hashes = possible_hashes.service_names.select { |name| file_hash.include?(name) } checked_hashes = VersionMetadataFile.calculate_hashes(full_path, file_hashes) checked_hashes.each_pair do |id, result| if file_hash[id] != result return false end end true end |