From 72976be7654ab9129b4ba7cd12339ebaa0fb8d55 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 5 Aug 2013 17:19:08 -0400 Subject: [PATCH] fix verifying a target's checksum --- lib/rscons/cache.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index c7d91e7..d289633 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -80,6 +80,7 @@ module Rscons # @return true value if the target is up to date, meaning that: # - the target exists on disk # - the cache has information for the target + # - the target's checksum matches its checksum when it was last built # - the command used to build the target is the same as last time # - all dependencies listed are also listed in the cache, or, if # :strict_deps was given in options, the list of dependencies is @@ -93,6 +94,9 @@ module Rscons # target must be registered in the cache return false unless @cache[:targets].has_key?(target) + # target must have the same checksum as when it was built last + return false unless @cache[:targets][target][:checksum] == lookup_checksum(target) + # command used to build target must be identical return false unless @cache[:targets][target][:command] == command @@ -141,7 +145,7 @@ module Rscons # Calculate and return a file's checksum # @param file [String] The file name. def calculate_checksum(file) - @lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file)).encode(__ENCODING__) rescue '' + @lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file, {mode: 'rb'})).encode(__ENCODING__) rescue '' end end end