lib/nanoc3/base/item_rep.rb in nanoc3-3.1.2 vs lib/nanoc3/base/item_rep.rb in nanoc3-3.1.3
- old
+ new
@@ -352,21 +352,21 @@
@created = !File.file?(self.raw_path)
if self.binary?
# Calculate hash of old content
if File.file?(self.raw_path)
- hash_old = hash(self.raw_path)
+ hash_old = hash_for_file(self.raw_path)
size_old = File.size(self.raw_path)
end
# Copy
FileUtils.cp(@filenames[:last], self.raw_path)
@written = true
# Check if file was modified
size_new = File.size(self.raw_path)
- hash_new = hash(self.raw_path) if size_old == size_new
+ hash_new = hash_for_file(self.raw_path) if size_old == size_new
@modified = (size_old != size_new || hash_old != hash_new)
else
# Remember old content
if File.file?(self.raw_path)
@old_content = File.read(self.raw_path)
@@ -486,10 +486,10 @@
'content will be available.'
nil
end
# Returns a hash of the given filename
- def hash(filename)
+ def hash_for_file(filename)
digest = Digest::SHA1.new
File.open(filename, 'r') do |io|
until io.eof
data = io.readpartial(2**10)
digest.update(data)