This class builds a checksum file of all files inside a given directory and then provides functions for comparing that directory against the checksum file for modifications. Three implementations are available, one based on md5, one based on sha1, and one based on file mtime.
gem install dir_checksum
github.com/ePublishing/dir_checksum
# Process checksum with a block (defaults to SHA1) DirChecksum.recursive_checksum('/a/directory') do |file, checksum| puts "#{file}: #{checksum}" end # Writes result of checksum to file in root of directory DirChecksum::MD5.write_to_file!('/some/absolute/directory') # Write result of checksum to (optional) output checksum file DirChecksum::SHA1.write_to_file!('some/relative/directory', 'checksum_output.txt') # If a checksum file exists (optionally pass in location), examine it # and compare those results with current directory to determine differences DirChecksum::Timestamp.warn_if_has_checksum_file_and_diff!('/a/directory')
- Author
-
David McCullars <[email protected]>
- Copyright
-
© 2011 ePublishing
- Licence