File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,10 @@ def compile(*args)
202202 logger . debug "Skipping #{ target } .gz, already exists"
203203 else
204204 logger . info "Writing #{ target } .gz"
205- concurrent_compressors << Concurrent ::Future . execute { write_file . wait! ; gzip . compress ( target ) }
205+ concurrent_compressors << Concurrent ::Future . execute do
206+ write_file . wait! if write_file
207+ gzip . compress ( target )
208+ end
206209 end
207210
208211 end
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ class Gzip
44 # Private: Generates a gzipped file based off of reference file.
55 def initialize ( asset )
66 @content_type = asset . content_type
7- @mtime = asset . mtime
87 @source = asset . source
98 @charset = asset . charset
109 end
@@ -42,11 +41,14 @@ def cannot_compress?(mime_types)
4241 #
4342 # Returns nothing.
4443 def compress ( target )
44+ mtime = PathUtils . stat ( target ) . mtime
4545 PathUtils . atomic_write ( "#{ target } .gz" ) do |f |
4646 gz = Zlib ::GzipWriter . new ( f , Zlib ::BEST_COMPRESSION )
47- gz . mtime = @ mtime. to_i
47+ gz . mtime = mtime
4848 gz . write ( @source )
4949 gz . close
50+
51+ File . utime ( mtime , mtime , f . path )
5052 end
5153
5254 nil
Original file line number Diff line number Diff line change @@ -636,6 +636,27 @@ def teardown
636636 original_path = @env [ file_name ] . digest_path
637637 manifest . compile ( file_name )
638638 assert File . exist? ( "#{ @dir } /#{ original_path } .gz" ) , "Expecting '#{ original_path } ' to generate gzipped file: '#{ original_path } .gz' but it did not"
639+ assert_equal File . stat ( "#{ @dir } /#{ original_path } " ) . mtime , Zlib ::GzipReader . open ( "#{ @dir } /#{ original_path } .gz" ) { |gz | gz . mtime }
640+ end
641+ end
642+
643+
644+ test "writes gzip files even if files were already on disk" do
645+ @env . gzip = false
646+ manifest = Sprockets ::Manifest . new ( @env , @dir )
647+ files = %W{ gallery.css application.js logo.svg }
648+ files . each do |file_name |
649+ original_path = @env [ file_name ] . digest_path
650+ manifest . compile ( file_name )
651+ assert File . exist? ( "#{ @dir } /#{ original_path } " ) , "Expecting \" #{ @dir } /#{ original_path } \" to exist but did not"
652+ end
653+
654+ @env . gzip = true
655+ files . each do |file_name |
656+ original_path = @env [ file_name ] . digest_path
657+ manifest . compile ( file_name )
658+ assert File . exist? ( "#{ @dir } /#{ original_path } .gz" ) , "Expecting '#{ original_path } ' to generate gzipped file: '#{ original_path } .gz' but it did not"
659+ assert_equal File . stat ( "#{ @dir } /#{ original_path } " ) . mtime , Zlib ::GzipReader . open ( "#{ @dir } /#{ original_path } .gz" ) { |gz | gz . mtime }
639660 end
640661 end
641662
You can’t perform that action at this time.
0 commit comments