lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.7 vs lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.8

- old
+ new

@@ -9,10 +9,11 @@ remotely_execute(ssh_info, "sudo rm -rf #{guestpath};") end def self.scp(machine, ssh_info, opts) guestpath = opts[:guestpath] + guestpath += "/" if !guestpath.end_with?("/") 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]) @@ -23,15 +24,16 @@ username = ssh_info[:username] host = ssh_info[:host] machine.ui.info("Sending #{hostpath} to #{guestpath}") - remotely_execute(ssh_info, "sudo mkdir -p #{guestpath}; sudo chown #{username}:$(id -gn #{username}) #{guestpath}") + remotely_execute(ssh_info, "sudo mkdir -p #{guestpath} 2> /dev/null; sudo chown #{username}:$(id -gn #{username}) #{guestpath}") - temp_file = `mktemp -t 'temp.XXXX.tar.gz'`.strip + temp_file = `mktemp -t 'temp.tar.gz' 2> /dev/null || mktemp -t 'temp.tar.gz.XXXX'`.strip + temp_file_name = Pathname.new(temp_file).basename machine.ui.info("Compressing #{hostpath} into #{temp_file}") - system("tar -czhf #{temp_file} -C #{hostpath} #{included_files}") + `tar -czhf #{temp_file} -C #{hostpath} #{included_files}` machine.ui.info("Copying #{temp_file} to #{guestpath}") command = [ "scp", '-o StrictHostKeyChecking=no', @@ -40,14 +42,13 @@ "-o port=#{ssh_info[:port]}", "-i '#{ssh_info[:private_key_path][0]}'", "#{temp_file}", "#{username}@#{host}:#{guestpath}" ].join(' ') - system(command) + `#{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") + remotely_execute(ssh_info, "tar -xzf #{guestpath}#{temp_file_name} -C #{guestpath}; rm #{guestpath}#{temp_file_name}") machine.ui.info("#{guestpath} synchronised") end def self.remotely_execute(ssh_info, command) ssh_command = [ @@ -58,10 +59,10 @@ "-o port=#{ssh_info[:port]}", "-i '#{ssh_info[:private_key_path][0]}'", "#{ssh_info[:username]}@#{ssh_info[:host]}", "'#{command}'" ].join(' ') - system(ssh_command) + `#{ssh_command}` end end end end