Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract to methods

to make copy cache process more readable
  • Loading branch information...
commit 1c1d3c3f323c47faf5cca7cc88f7d0051e44250c 1 parent c789f99
@despo authored
Showing with 40 additions and 17 deletions.
  1. +40 −17 lib/capistrano/recipes/deploy/strategy/copy.rb
View
57 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -122,34 +122,53 @@ def last_command_failed?
end
def copy_cache_to_staging_area
- FileUtils.mkdir_p(destination)
logger.debug "copying cache to deployment staging area #{destination}"
+ create_destination
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.concat queue_files("#{item}/*")
- FileUtils.mkdir(File.join(destination, item))
- else
- FileUtils.ln(item, File.join(destination, item))
- end
- end
+ copy_files(queue_files)
end
end
- def queue_files directory="*"
- Dir.glob(directory, File::FNM_DOTMATCH).reject! { |file| excluded_files_contain? file }
+ def create_destination
+ FileUtils.mkdir_p(destination)
+ end
+
+ def copy_files files
+ files.each { |filename| process_file(filename) }
+ end
+
+ def process_file filename
+ return copy_symlink(filename) if File.symlink? filename
+ return copy_directory(filename) if File.directory? filename
+ copy_hardlink filename
+ end
+
+ def copy_symlink name
+ FileUtils.ln_s(File.readlink(item), File.join(destination, name))
+ end
+
+ def copy_directory name
+ FileUtils.mkdir(File.join(destination, name))
+ copy_files(queue_files(name))
+ end
+
+ def copy_hardlink name
+ FileUtils.ln(name, File.join(destination, name))
+ end
+
+ def queue_files directory=nil
+ Dir.glob(pattern_for(directory), File::FNM_DOTMATCH).reject! { |file| excluded_files_contain? file }
+ end
+
+ def pattern_for directory
+ !directory.nil? ? "#{directory}/*" : "*"
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)
@@ -274,10 +293,14 @@ def decompress(file)
compression.decompress_command + [file]
end
+ def decompress_remote_file
+ run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
+ end
+
# Distributes the file to the remote servers
def distribute!
upload(filename, remote_filename)
- run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
+ decompress_remote_file
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.