Skip to content

Commit

Permalink
Do not fail when asset was already compiled
Browse files Browse the repository at this point in the history
In the case where a deploy was happening after all the assets were already generated, a future to write a file to disk is not created, (i.e. in the "skipped writing" file code path). We now check for the presence of this future before trying to `wait!` on it.
  • Loading branch information
schneems committed Dec 5, 2015
1 parent f5a9dde commit 8ec4c82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sprockets/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def compile(*args)
else
logger.info "Writing #{target}.gz"
concurrent_compressors << Concurrent::Future.execute do
write_file.wait!
write_file.wait! if write_file
gzip.compress(target)
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/test_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,26 @@ def teardown
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

test "disable file gzip" do
@env.gzip = false
manifest = Sprockets::Manifest.new(@env, @dir)
Expand Down

0 comments on commit 8ec4c82

Please sign in to comment.