Skip to content

Commit

Permalink
Merge pull request #283 from k0kubun/send_directory
Browse files Browse the repository at this point in the history
Create send_directory backend command
  • Loading branch information
mizzy committed Dec 23, 2014
2 parents 20d2259 + 46257f7 commit 1fcde40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/specinfra/backend/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def send_file(from, to)
FileUtils.cp(from, to)
end

def send_directory(from, to)
FileUtils.cp_r(from, to)
end

def build_command(cmd)
shell = Specinfra.configuration.shell || '/bin/sh'
cmd = cmd.shelljoin if cmd.is_a?(Array)
Expand Down
24 changes: 16 additions & 8 deletions lib/specinfra/backend/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ def run_command(cmd, opt={})
end

def send_file(from, to)
if Specinfra.configuration.scp.nil?
Specinfra.configuration.scp = create_scp
end
scp_upload!(from, to)
end

tmp = File.join('/tmp', File.basename(to))
scp = Specinfra.configuration.scp
scp.upload!(from, tmp)
run_command(Specinfra.command.get(:move_file, tmp, to))
def send_directory(from, to)
scp_upload!(from, to, :recursive => true)
end

def build_command(cmd)
Expand Down Expand Up @@ -84,7 +81,18 @@ def create_scp
end
Net::SCP.new(ssh)
end


def scp_upload!(from, to, opt={})
if Specinfra.configuration.scp.nil?
Specinfra.configuration.scp = create_scp
end

tmp = File.join('/tmp', File.basename(to))
scp = Specinfra.configuration.scp
scp.upload!(from, tmp, opt)
run_command(Specinfra.command.get(:move_file, tmp, to))
end

def ssh_exec!(command)
stdout_data = ''
stderr_data = ''
Expand Down

0 comments on commit 1fcde40

Please sign in to comment.