Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
merge asset directories
def symlink_r(source, dest)
# recursively symlinks a directory tree.
# skips files that already exist.
::Dir.glob(::File.join(source, "**", "*")).each do |f|
next if ::File.directory?(f)
new_name = ::File.join(dest, f.gsub(/^#{source}/, "") )
next if ::File.exists?(new_name) or ::File.symlink?(new_name)
::FileUtils.mkdir_p(::File.dirname(new_name))
#puts "trying #{f} => #{new_name}"
::File.symlink(f, new_name)
end
end
namespace :indigo do
desc "Merge public assets, so apache can find them all"
task :merge_assets do
raise "missing releases_path" unless ENV['releases_path']
raise "missing release_name" unless ENV['release_name']
releases_path = ENV['releases_path']
release_name = unless ENV['release_name']
merged_dir = ::File.join(releases_path, release_name, "public_merged")
# First, make the merged dir, and symlink in the current release
::FileUtils.remove_dir(merged_dir, :force => true)
::FileUtils.mkdir_p(merged_dir)
symlink_r(::File.join(releases_path, release_name, "public"), merged_dir)
# now, iterate over the older releases and symlink them in.
# do this newest first. This will interate over the current_release again.
# But I suspect it has many inefficiencies in diskio.
::Dir.glob(::File.join(releases_path,"*")).sort.reverse.each do |old_release|
symlink_r(::File.join(old_release, "public"), merged_dir)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment