Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/sprockets/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def compile(*args)
logger.debug "Skipping #{target}.gz, already exists"
else
logger.info "Writing #{target}.gz"
concurrent_compressors << Concurrent::Future.execute { write_file.wait!; gzip.compress(target) }
concurrent_compressors << Concurrent::Future.execute do
write_file.wait! if write_file
gzip.compress(target)
end
end

end
Expand Down
6 changes: 4 additions & 2 deletions lib/sprockets/utils/gzip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Gzip
# Private: Generates a gzipped file based off of reference file.
def initialize(asset)
@content_type = asset.content_type
@mtime = asset.mtime
@source = asset.source
@charset = asset.charset
end
Expand Down Expand Up @@ -42,11 +41,14 @@ def cannot_compress?(mime_types)
#
# Returns nothing.
def compress(target)
mtime = PathUtils.stat(target).mtime
PathUtils.atomic_write("#{target}.gz") do |f|
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
gz.mtime = @mtime.to_i
gz.mtime = mtime
gz.write(@source)
gz.close

File.utime(mtime, mtime, f.path)
end

nil
Expand Down
21 changes: 21 additions & 0 deletions test/test_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,27 @@ def teardown
original_path = @env[file_name].digest_path
manifest.compile(file_name)
assert File.exist?("#{@dir}/#{original_path}.gz"), "Expecting '#{original_path}' to generate gzipped file: '#{original_path}.gz' but it did not"
assert_equal File.stat("#{@dir}/#{original_path}").mtime, Zlib::GzipReader.open("#{@dir}/#{original_path}.gz") {|gz| gz.mtime }
end
end


test "writes gzip files even if files were already on disk" do
@env.gzip = false
manifest = Sprockets::Manifest.new(@env, @dir)
files = %W{ gallery.css application.js logo.svg }
files.each do |file_name|
original_path = @env[file_name].digest_path
manifest.compile(file_name)
assert File.exist?("#{@dir}/#{original_path}"), "Expecting \"#{@dir}/#{original_path}\" to exist but did not"
end

@env.gzip = true
files.each do |file_name|
original_path = @env[file_name].digest_path
manifest.compile(file_name)
assert File.exist?("#{@dir}/#{original_path}.gz"), "Expecting '#{original_path}' to generate gzipped file: '#{original_path}.gz' but it did not"
assert_equal File.stat("#{@dir}/#{original_path}").mtime, Zlib::GzipReader.open("#{@dir}/#{original_path}.gz") {|gz| gz.mtime }
end
end

Expand Down