Sha256: 70552fd6391efda97e9a80c7fef23b2fbe63f6dc7e744710237a2d2846ac5808

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

namespace(:deploy) do
  desc "Symlink shared files and directories."
  task(:symlink_files) do
    [:shared_dirs, :shared_files].map { |var| fetch(var, []) }.flatten.each do |path|
      source      = "#{latest_release}/#{path}"
      destination = "#{shared_path}/#{path}"
      
      d = destination
      dp = File.dirname(destination)
      p = previous_release
      r = path
      s = source
      
      run <<-CMD
        [ -e #{d} ] || { mkdir -p #{dp} && { if [[ "#{p}" ]] && [ -e #{p}/#{r} ]; then cp -r #{p}/#{r} #{d}; elif [ -e #{s} ]; then cp -r #{s} #{d}; fi } };
        rm -rf #{source} && ln -nfs #{destination} #{source}
      CMD
    end
  end
  after('deploy:finalize_update') { symlink_files }
  
  task :delete_mac_os_metadata_files do
    run "cd #{latest_release} && find . | egrep '(^|/)\\._' | xargs rm 2>/dev/null; true"
  end
  after('deploy:finalize_update') { delete_mac_os_metadata_files }
  
  desc "Download files from the current revision."
  task :download do
    (ENV["FILES"] || "").split(",").each do |path|
      path = path.strip
      top.download(File.join(current_path, path), path)
    end
  end
end

# Capistrano assumes assets are placed under public/ but static or PHP sites
# usually don't have such a separate directory for assets, since they're made of
# such files. Accommodate to its default behaviour by symlinking appropriately.
def root_contains_assets!
  after('deploy:finalize_update') do
    run %w(images stylesheets javascripts).map { |dir| "ln -ns ../#{dir} #{latest_release}/public/#{dir}" }.join('; ')
    run "ln -ns public/system #{latest_release}/system"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
Roman2K-capistrano-fixes-0.1.2 lib/capistrano_fixes/tasks.rb
Roman2K-capistrano-fixes-0.1.3 lib/capistrano_fixes/tasks.rb