Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

extract copy and copy cache strategies to…

 their own methods

change file processing to use File.ftype method and change tests to reflect that
  • Loading branch information...
commit 5752213950b2bd19e30d016648c981a1ccef392c 1 parent 41af69c
@despo authored
View
48 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -55,15 +55,9 @@ class Copy < Base
# directory.
def deploy!
if copy_cache
- copy_repository_to_local_cache
- run_build_script_on copy_cache
-
- copy_cache_to_staging_area
+ run_copy_cache_strategy
else
- copy_repository_to_server
- run_build_script_on destination
-
- remove_excluded_files if copy_exclude.any?
+ run_copy_strategy
end
create_revision_file
@@ -74,11 +68,9 @@ def deploy!
end
def run_build_script_on directory
- return unless build_script
-
execute "running build script on #{directory}" do
Dir.chdir(directory) { system(build_script) }
- end
+ end if build_script
end
def check!
@@ -101,6 +93,18 @@ def copy_cache
private
+ def run_copy_cache_strategy
+ copy_repository_to_local_cache
+ run_build_script_on copy_cache
+ copy_cache_to_staging_area
+ end
+
+ def run_copy_strategy
+ copy_repository_to_server
+ run_build_script_on destination
+ remove_excluded_files if copy_exclude.any?
+ end
+
def execute description, &block
logger.debug description
handle_system_errors &block
@@ -134,10 +138,7 @@ def last_command_failed?
def copy_cache_to_staging_area
execute "copying cache to deployment staging area #{destination}" do
create_destination
-
- Dir.chdir(copy_cache) do
- copy_files(queue_files)
- end
+ Dir.chdir(copy_cache) { copy_files(queue_files) }
end
end
@@ -150,13 +151,12 @@ def copy_files files
end
def process_file name
- return copy_symlink(name) if File.symlink? name
- return copy_directory(name) if File.directory? name
- copy_hardlink name
+ filetype = File.ftype(name)
+ send "copy_#{filetype}", name
end
- def copy_symlink name
- FileUtils.ln_s(File.readlink(item), File.join(destination, name))
+ def copy_link name
+ FileUtils.ln_s(File.readlink(name), File.join(destination, name))
end
def copy_directory name
@@ -164,7 +164,7 @@ def copy_directory name
copy_files(queue_files(name))
end
- def copy_hardlink name
+ def copy_file name
FileUtils.ln(name, File.join(destination, name))
end
@@ -182,10 +182,14 @@ def excluded_files_contain? file
def copy_repository_to_server
execute "getting (via #{copy_strategy}) revision #{revision} to #{destination}" do
- system(command)
+ copy_repository_via_strategy
end
end
+ def copy_repository_via_strategy
+ system(command)
+ end
+
def remove_excluded_files
logger.debug "processing exclusions..."
View
6 test/deploy/strategy/copy_test.rb
@@ -306,15 +306,15 @@ def test_with_build_script_should_run_script
def prepare_directory_tree!(cache, exclude=false)
Dir.expects(:glob).with("*", File::FNM_DOTMATCH).returns([".", "..", "app", "foo.txt"])
- File.expects(:directory?).with("app").returns(true)
+ File.expects(:ftype).with("app").returns("directory")
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
- File.expects(:directory?).with("foo.txt").returns(false)
+ File.expects(:ftype).with("foo.txt").returns("file")
FileUtils.expects(:ln).with("foo.txt", "/temp/dir/1234567890/foo.txt")
Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
unless exclude
- File.expects(:directory?).with("app/bar.txt").returns(false)
+ File.expects(:ftype).with("app/bar.txt").returns("file")
FileUtils.expects(:ln).with("app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.