synced_folders/rsync: convert path to cygpath on Windows

This commit is contained in:
Mitchell Hashimoto 2014-01-15 21:13:08 -08:00
parent 285bda7a68
commit 73b72deb0a
3 changed files with 40 additions and 4 deletions

View File

@ -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

View File

@ -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]

View File

@ -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, "", ""))