Created
May 20, 2014 15:01
-
-
Save wheresalice/468c89b85051ea369d1e to your computer and use it in GitHub Desktop.
check a crc file matches a datafile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_crc(crc_file, datafile) | |
expected_crc = File.read(crc_file).split(' ') | |
actual_crc = `cksum #{datafile}`.split(' ') | |
unless File.exist?(crc_file) | |
puts 'crc file missing' | |
return false | |
end | |
unless File.exist?(datafile) | |
puts 'datafile missing' | |
return false | |
end | |
unless expected_crc[1] == actual_crc[1] | |
puts 'filesize mismatch' | |
return false | |
end | |
unless expected_crc[0] == actual_crc[0] | |
puts 'checksum mismatch' | |
return false | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment