From 73b72deb0ad7bb2ac41811fa989a5c4938dc26df Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 15 Jan 2014 21:13:08 -0800 Subject: [PATCH] synced_folders/rsync: convert path to cygpath on Windows --- lib/vagrant/util/platform.rb | 16 ++++++++++---- plugins/synced_folders/rsync/helper.rb | 6 +++++ .../synced_folders/rsync/helper_test.rb | 22 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 1ebc08f71..f86bcfddf 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -33,11 +33,19 @@ module Vagrant # path on Windows machines in Cygwin. # # @return [String] - def cygwin_windows_path(path) - return path if !cygwin? + def cygwin_windows_path(path, **opts) + return path if !cygwin? && !opts[:force] - process = Subprocess.execute("cygpath", "-w", "-l", "-a", path.to_s) - process.stdout.chomp + begin + # First try the real cygpath + process = Subprocess.execute("cygpath", "-w", "-l", "-a", path.to_s) + return process.stdout.chomp + rescue Errors::CommandUnavailableWindows + # Sometimes cygpath isn't available (msys). Instead, do what we + # can with bash tricks. + process = Subprocess.execute("bash", "-c", "cd #{path} && pwd") + return process.stdout.chomp + end end # This checks if the filesystem is case sensitive. This is not a diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index cef789bf7..0afb1c0f2 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -13,6 +13,12 @@ module VagrantPlugins hostpath = File.expand_path(hostpath, machine.env.root_path) hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s + if Vagrant::Util::Platform.windows? + # rsync for Windows expects cygwin style paths + hostpath = Vagrant::Util::Platform.cygwin_windows_path( + hostpath, force: true) + end + # Connection information username = ssh_info[:username] host = ssh_info[:host] diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index a8505ff36..28e2b58eb 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -21,6 +21,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do before do machine.stub(guest: guest) + + # Don't do all the crazy Cygwin stuff + Vagrant::Util::Platform.stub(:cygwin_windows_path) do |path, **opts| + path + end end describe "#rsync_single" do @@ -44,6 +49,23 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do subject.rsync_single(machine, ssh_info, opts) end + it "doesn't call cygwin_windows_path on non-Windows" do + Vagrant::Util::Platform.stub(windows?: false) + Vagrant::Util::Platform.should_not_receive(:cygwin_windows_path) + subject.rsync_single(machine, ssh_info, opts) + end + + it "calls cygwin_windows_path on Windows" do + Vagrant::Util::Platform.stub(windows?: true) + Vagrant::Util::Platform.should_receive(:cygwin_windows_path).and_return("foo") + + Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(args[args.length - 3]).to eql("foo") + end + + subject.rsync_single(machine, ssh_info, opts) + end + it "raises an error if the exit code is non-zero" do Vagrant::Util::Subprocess.stub( execute: Vagrant::Util::Subprocess::Result.new(1, "", ""))