diff --git a/lib/capistrano/recipes/deploy/assets.rb b/lib/capistrano/recipes/deploy/assets.rb index a3c4fdf70..08f495d7e 100644 --- a/lib/capistrano/recipes/deploy/assets.rb +++ b/lib/capistrano/recipes/deploy/assets.rb @@ -34,6 +34,14 @@ def parse_manifest(str) assets_hash.to_a.flatten.map {|a| [a, "#{a}.gz"]}.flatten end +def number_of_manifests + output = capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\"") + # splitting on "." because File.basename(path, ".*") only removes the *first* extension, so for x.js.gz, it will return x.js + output = output.map { |path| File.basename(path).split(".")[0] } + # we may get manifest-X.js and manifest-X.js.gz, so we shouldn't count those as unique manifests + return output.uniq.size +end + namespace :deploy do namespace :assets do desc <<-DESC @@ -91,10 +99,9 @@ def parse_manifest(str) logger.info 'Ignoring multiple asset/clean_expired manifests...' end if should_retry_if_multi - # test for multiple - if capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\" | wc -l").to_i > 1 + if number_of_manifests > 1 logger.info "Multiple manifest assets detected; clearing old assets..." - run "mv #{shared_path.shellescape}/#{shared_assets_prefix} '/tmp/#{shared_assets_prefix}-#{Time.now.to_s}'" + run "mv #{shared_path.shellescape}/#{shared_assets_prefix} '/tmp/#{shared_assets_prefix}-#{Time.now.to_s}' && mkdir #{shared_path.shellescape}/#{shared_assets_prefix} && chmod 775 #{shared_path.shellescape}/#{shared_assets_prefix}" run <<-CMD.compact sudo -n rm -f /tmp/assets-precompile-output*.log > /dev/null || true ; #{precompile_command} @@ -104,7 +111,7 @@ def parse_manifest(str) end # test again - if capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\" | wc -l").to_i > 1 + if number_of_manifests > 1 logger.info "Multiple manifest assets still detected; skipping..." end