From fdd8a65bc832d8e49575897aa003082689a2c7d3 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Mon, 22 Jan 2007 15:37:35 +0000 Subject: [PATCH] Add a "get" helper, to pull a file from a remote server to the localhost (closes #6978). Also, fix a typo in standard.rb that caused a syntax error. git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6009 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ lib/capistrano/actor.rb | 28 ++++++++++++++++++++++++++++ lib/capistrano/recipes/standard.rb | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 23b7e1d2..ea1721d0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add a "get" helper, to pull a file from a remote server to the localhost [bmihelac] + * Fix gateway to actually increment local_port if a port is in use, so that multiple capistrano instances can run at the same time [Mark Imbriaco] * Refactor the permissions tweaking in update_code to a separate task so that people on shared hosts can override it as necessary [jaw6] diff --git a/lib/capistrano/actor.rb b/lib/capistrano/actor.rb index c0346cda..ae391eb5 100644 --- a/lib/capistrano/actor.rb +++ b/lib/capistrano/actor.rb @@ -261,6 +261,34 @@ module Capistrano end end end + + # Get file remote_path from FIRST server targetted by + # the current task and transfer it to local machine as path. It will use + # SFTP if Net::SFTP is installed; otherwise it will fall back to using + # 'cat', which may cause corruption in binary files. + # + # get "#{deploy_to}/current/log/production.log", "log/production.log.web" + def get(remote_path, path, options = {}) + if Capistrano::SFTP && options.fetch(:sftp, true) + execute_on_servers(options.merge(:once => true)) do |servers| + logger.debug "downloading #{servers.first}:#{remote_path} to #{path}" + sessions[servers.first].sftp.connect do |tsftp| + tsftp.get_file remote_path, path + end + logger.trace "download finished" + end + else + logger.important "Net::SFTP is not available; using remote 'cat' to get file, which may cause file corruption" + File.open(path, "w") do |destination| + run "cat #{remote_path}", :once => true do |ch, stream, data| + case stream + when :out then destination << data + when :err then raise "error while downloading #{remote_path}: #{data.inspect}" + end + end + end + end + end # Like #run, but executes the command via sudo. This assumes that # the sudo password (if required) is the same as the password for logging diff --git a/lib/capistrano/recipes/standard.rb b/lib/capistrano/recipes/standard.rb index 7e35cc3b..3991ac51 100644 --- a/lib/capistrano/recipes/standard.rb +++ b/lib/capistrano/recipes/standard.rb @@ -66,7 +66,7 @@ desc <<-DESC Sets group permissions on checkout. Useful for team environments, bad on shared hosts. Override this task if you're on a shared host. DESC -task :set_permissions +task :set_permissions do run "chmod -R g+w #{release_path}" end