Skip to content

Commit

Permalink
move copy of cache to server to its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
despo committed Mar 16, 2012
1 parent 6e17f9f commit 8586954
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/capistrano/recipes/deploy/strategy/copy.rb
Expand Up @@ -64,29 +64,7 @@ def deploy!
rollback_changes if last_command_failed?

build(copy_cache)

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) }

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)
FileUtils.mkdir(File.join(destination, item))
else
FileUtils.ln(item, File.join(destination, item))
end
end
end
copy_cache_to_server
else
logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
system(command)
Expand Down Expand Up @@ -164,6 +142,31 @@ def last_command_failed?
$? != 0
end

def copy_cache_to_server
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) }

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)
FileUtils.mkdir(File.join(destination, item))
else
FileUtils.ln(item, File.join(destination, item))
end
end
end
end

# Specify patterns to exclude from the copy. This is only valid
# when using a local cache.
def copy_exclude
Expand Down

0 comments on commit 8586954

Please sign in to comment.