Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Created May 20, 2014 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheresalice/468c89b85051ea369d1e to your computer and use it in GitHub Desktop.
Save wheresalice/468c89b85051ea369d1e to your computer and use it in GitHub Desktop.
check a crc file matches a datafile
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