Merge pull request #399 from bhollis/gzip
Synchronize gzipped file mtimes with their source file's mtime
This commit is contained in:
commit
7694ef6e07
1 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue