lib/cocoapods-binary-cache/helper/checksum.rb in cocoapods-binary-cache-0.1.5 vs lib/cocoapods-binary-cache/helper/checksum.rb in cocoapods-binary-cache-0.1.6
- old
+ new
@@ -2,11 +2,17 @@
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
require "digest/md5"
class FolderChecksum
- def self.checksum(dir)
- files = Dir["#{dir}/**/*"].reject { |f| File.directory?(f) }
- content = files.map { |f| File.read(f) }.join
- Digest::MD5.hexdigest(content).to_s
+ def self.git_checksum(dir)
+ checksum_of_files(`git ls-files #{dir}`.split("\n"))
+ rescue => e
+ Pod::UI.warn "Cannot get checksum of tracked files under #{dir}: #{e}"
+ checksum_of_files(Dir["#{dir}/**/*"].reject { |f| File.directory?(f) })
+ end
+
+ def self.checksum_of_files(files)
+ checksums = files.sort.map { |f| Digest::MD5.hexdigest(File.read(f)) }
+ Digest::MD5.hexdigest(checksums.join)
end
end