Permalink
Browse files

separate copying cache to more readable methods

  • Loading branch information...
despo committed Mar 18, 2012
1 parent fe76b89 commit c789f99e2ec3fdf8d466a5bcf89ff06f98c11c0e
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -123,21 +123,16 @@ def last_command_failed?
def copy_cache_to_staging_area
FileUtils.mkdir_p(destination)
-
logger.debug "copying cache to deployment staging area #{destination}"
- Dir.chdir(copy_cache) do
- queue = Dir.glob("*", File::FNM_DOTMATCH)
- while queue.any?
- item = queue.shift
- name = File.basename(item)
- next if name == "." || name == ".."
- next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
+ Dir.chdir(copy_cache) do
+ queue = queue_files
+ queue.each do |item|
if File.symlink?(item)
FileUtils.ln_s(File.readlink(item), File.join(destination, item))
elsif File.directory?(item)
- queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
+ queue.concat queue_files("#{item}/*")
FileUtils.mkdir(File.join(destination, item))
else
FileUtils.ln(item, File.join(destination, item))
@@ -146,6 +141,15 @@ def copy_cache_to_staging_area
end
end
+ def queue_files directory="*"
+ Dir.glob(directory, File::FNM_DOTMATCH).reject! { |file| excluded_files_contain? file }
+ end
+
+ def excluded_files_contain? file
+ copy_exclude.any? { |p| File.fnmatch(p, file) } or [ ".", ".."].include? File.basename(file)
+ end
+
+
def copy_repository_to_server
logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
system(command)

0 comments on commit c789f99

Please sign in to comment.