lib/nanoc3/base/item_rep.rb in nanoc3-3.1.3 vs lib/nanoc3/base/item_rep.rb in nanoc3-3.1.4
- old
+ new
@@ -355,26 +355,31 @@
# Calculate hash of old content
if File.file?(self.raw_path)
hash_old = hash_for_file(self.raw_path)
size_old = File.size(self.raw_path)
end
+ size_new = File.size(@filenames[:last])
+ hash_new = hash_for_file(@filenames[:last]) if size_old == size_new
- # 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_for_file(self.raw_path) if size_old == size_new
@modified = (size_old != size_new || hash_old != hash_new)
+
+ # Copy
+ if @modified
+ FileUtils.cp(@filenames[:last], self.raw_path)
+ end
+ @written = true
else
# Remember old content
if File.file?(self.raw_path)
@old_content = File.read(self.raw_path)
end
# Write
- File.open(self.raw_path, 'w') { |io| io.write(@content[:last]) }
+ new_content = @content[:last]
+ if @old_content != new_content
+ File.open(self.raw_path, 'w') { |io| io.write(new_content) }
+ end
@written = true
# Generate diff
generate_diff