lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.4 vs lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.5

- old
+ new

@@ -1,50 +1,51 @@ module Vagrant module Zscp # This is a helper that abstracts out the functionality of scping # folders so that it can be called from anywhere. class ZscpHelper + def self.cleanup(machine, ssh_info, opts) + guestpath = opts[:guestpath] + machine.ui.info("Removing remote #{guestpath}") + remotely_execute(ssh_info, "sudo rm -rf #{guestpath};") + end + def self.scp(machine, ssh_info, opts) guestpath = opts[:guestpath] - hostpath = opts[:hostpath] - hostpath = File.expand_path(hostpath, machine.env.root_path) + hostpath = File.expand_path(opts[:hostpath], machine.env.root_path) hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s + hostpath += "/" if !hostpath.end_with?("/") + if (opts[:zscp_include]) included_files = opts[:zscp_include].join(' ') else included_files = '.' end username = ssh_info[:username] host = ssh_info[:host] - if !hostpath.end_with?("/") - hostpath += "/" - end - machine.ui.info("Sending #{hostpath} to #{guestpath}") - machine.ui.info("Removing remote #{guestpath}") - remotely_execute(ssh_info, "sudo rm -rf #{guestpath}; sudo mkdir -p #{guestpath}; sudo chown #{username}:$(id -gn) #{guestpath}") + remotely_execute(ssh_info, "sudo mkdir -p #{guestpath}; sudo chown #{username}:$(id -gn #{username}) #{guestpath}") - temp_file = `mktemp -t 'temp.XXXX.tar.gz'`.strip + temp_file = `mktemp -t 'temp.XXXX.tar.gz'`.strip + machine.ui.info("Compressing #{hostpath} into #{temp_file}") + system("tar -czhf #{temp_file} -C #{hostpath} #{included_files}") - machine.ui.info("Compressing #{hostpath} into #{temp_file}") - system("tar -czhf #{temp_file} -C #{hostpath} #{included_files}") + machine.ui.info("Copying #{temp_file} to #{guestpath}") + command = [ + "scp", + '-o StrictHostKeyChecking=no', + '-o UserKnownHostsFile=/dev/null', + "-o port=#{ssh_info[:port]}", + "-i '#{ssh_info[:private_key_path][0]}'", + "#{temp_file}", + "#{username}@#{host}:#{guestpath}" + ].join(' ') + system(command) - machine.ui.info("Copying #{temp_file} to #{guestpath}") - command = [ - "scp", - '-o StrictHostKeyChecking=no', - '-o UserKnownHostsFile=/dev/null', - "-o port=#{ssh_info[:port]}", - "-i '#{ssh_info[:private_key_path][0]}'", - "#{temp_file}", - "#{username}@#{host}:#{guestpath}" - ].join(' ') - system(command) - - machine.ui.info("Extracting remotely #{guestpath}/temp.*.tar.gz") - remotely_execute(ssh_info, "tar -xzf #{guestpath}/temp.*.tar.gz -C #{guestpath}; rm #{guestpath}/temp.*.tar.gz") + machine.ui.info("Extracting remotely #{guestpath}/temp.*.tar.gz") + remotely_execute(ssh_info, "tar -xzf #{guestpath}/temp.*.tar.gz -C #{guestpath}; rm #{guestpath}/temp.*.tar.gz") machine.ui.info("#{guestpath} synchronised") end def self.remotely_execute(ssh_info, command) ssh_command = [