Skip to content

Commit f5a9dde

Browse files
committed
Asset#mtime was deprecated and not the correct value
This change pulls mtime from stat instead of relying on the asset object. Reference: 16ccffc#commitcomment-14779288 We don't need to use the environment stat cache because this file has likely never been stat-ed before. We also need to explicitly set the mtime of the file since it appears setting the mtime header has no impact on the mtime of the decompressed file.
1 parent 03048cb commit f5a9dde

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/sprockets/manifest.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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!
207+
gzip.compress(target)
208+
end
206209
end
207210

208211
end

lib/sprockets/utils/gzip.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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

test/test_manifest.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ 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 }
639640
end
640641
end
641642

0 commit comments

Comments
 (0)