def write(snapshot=:last)
raw_path = self.raw_path(:snapshot => snapshot)
return if raw_path.nil?
FileUtils.mkdir_p(File.dirname(raw_path))
is_created = !File.file?(raw_path)
if File.file?(raw_path)
hash_old = Pathname.new(raw_path).checksum
size_old = File.size(raw_path)
end
Nanoc::NotificationCenter.post(:will_write_rep, self, snapshot)
if self.binary?
size_new = File.size(temporary_filenames[:last])
hash_new = Pathname.new(temporary_filenames[:last]).checksum if size_old == size_new
is_modified = (size_old != size_new || hash_old != hash_new)
if is_modified
FileUtils.cp(temporary_filenames[:last], raw_path)
end
else
is_modified = (!File.file?(raw_path) || File.read(raw_path) != @content[:last])
if is_modified
File.open(raw_path, 'w') { |io| io.write(@content[:last]) }
end
end
Nanoc::NotificationCenter.post(:rep_written, self, raw_path, is_created, is_modified)
end