lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.2 vs lib/vagrant/zscp/helper.rb in vagrant-zscp-0.1.3
- old
+ new
@@ -20,32 +20,45 @@
if !hostpath.end_with?("/")
hostpath += "/"
end
machine.ui.info("Sending #{hostpath} to #{guestpath}")
- Dir.mktmpdir { |dir|
machine.ui.info("Removing remote #{guestpath}")
- machine.communicate.execute("sudo rm -rf #{guestpath}; sudo mkdir -p #{guestpath}; sudo chown #{username}:$(id -gn) #{guestpath}")
+ remotely_execute(ssh_info, "sudo rm -rf #{guestpath}; sudo mkdir -p #{guestpath}; sudo chown #{username}:$(id -gn) #{guestpath}")
- machine.ui.info("Compressing #{hostpath} into #{dir}/temp.tar.gz")
- `tar -czLf #{dir}/temp.tar.gz -C #{hostpath} #{included_files}`
+ temp_file = `mktemp -t 'temp.XXXX.tar.gz'`.strip
- machine.ui.info("Copying #{dir}/temp.tar.gz to #{guestpath}")
+ machine.ui.info("Compressing #{hostpath} into #{temp_file}")
+ system("tar -czLf #{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]}'",
- "#{dir}/temp.tar.gz",
+ "#{temp_file}",
"#{username}@#{host}:#{guestpath}"
].join(' ')
system(command)
- machine.ui.info("Extracting remotely #{guestpath}/temp.tar.gz")
- machine.communicate.execute("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 = [
+ 'ssh',
+ '-o StrictHostKeyChecking=no',
+ '-o UserKnownHostsFile=/dev/null',
+ "-o port=#{ssh_info[:port]}",
+ "-i '#{ssh_info[:private_key_path][0]}'",
+ "#{ssh_info[:username]}@#{ssh_info[:host]}",
+ "'#{command}'"
+ ].join(' ')
+ system(ssh_command)
end
end
end
end
\ No newline at end of file