From 9b9c95bd36306ef2da9ab2400c0bb507d7cfdd56 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Fri, 27 Apr 2012 22:25:45 -0700 Subject: [PATCH] Synchronize gzipped file mtimes with their source file's mtime --- .../lib/middleman-more/extensions/gzip.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/middleman-more/lib/middleman-more/extensions/gzip.rb b/middleman-more/lib/middleman-more/extensions/gzip.rb index 07ae563b..6e574148 100644 --- a/middleman-more/lib/middleman-more/extensions/gzip.rb +++ b/middleman-more/lib/middleman-more/extensions/gzip.rb @@ -39,12 +39,26 @@ module Middleman::Extensions def gzip_file(path, builder) input_file = File.open(path, 'r').read output_filename = path + '.gz' + input_file_time = File.mtime(path) + + # Check if the right file's already there + if File.exist?(output_filename) && File.mtime(output_filename) == input_file_time + return + end + File.open(output_filename, 'w') do |f| gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION) + gz.mtime = input_file_time.to_i gz.write input_file gz.close end + # Make the file times match, both for Nginx's gzip_static extension + # and so we can ID existing files. Also, so even if the GZ files are + # wiped out by build --clean and recreated, we won't rsync them over + # again because they'll end up with the same mtime. + File.utime(File.atime(output_filename), input_file_time, output_filename) + old_size = File.size(path) new_size = File.size(output_filename)