diff --git a/plugins/guests/windows/cap/rsync.rb b/plugins/guests/windows/cap/rsync.rb index e391b92db..aa9f1bcdf 100644 --- a/plugins/guests/windows/cap/rsync.rb +++ b/plugins/guests/windows/cap/rsync.rb @@ -2,8 +2,17 @@ module VagrantPlugins module GuestWindows module Cap class RSync + def self.rsync_scrub_guestpath( machine, opts ) + # Windows guests most often use cygwin-dependent rsync utilities + # that expect "/cygdrive/c" instead of "c:" as the path prefix + # some vagrant code may pass guest paths with drive-lettered paths here + opts[:guestpath].gsub( /^([a-zA-Z]):/, '/cygdrive/\1' ) + end + def self.rsync_pre(machine, opts) machine.communicate.tap do |comm| + # rsync does not construct any gaps in the path to the target directory + # make sure that all subdirectories are created comm.execute("mkdir '#{opts[:guestpath]}'") end end diff --git a/plugins/guests/windows/plugin.rb b/plugins/guests/windows/plugin.rb index 47ca67e3f..d22dc2743 100644 --- a/plugins/guests/windows/plugin.rb +++ b/plugins/guests/windows/plugin.rb @@ -64,6 +64,11 @@ module VagrantPlugins Cap::MountSharedFolder end + guest_capability(:windows, :rsync_scrub_guestpath) do + require_relative "cap/rsync" + Cap::RSync + end + guest_capability(:windows, :rsync_pre) do require_relative "cap/rsync" Cap::RSync diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index 594410436..e155d61f7 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -38,6 +38,11 @@ module VagrantPlugins hostpath = File.expand_path(hostpath, machine.env.root_path) hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s + # if the guest has a guest path scrubber capability, use it + if machine.guest.capability?(:rsync_scrub_guestpath) + guestpath = machine.guest.capability(:rsync_scrub_guestpath, opts) + end + if Vagrant::Util::Platform.windows? # rsync for Windows expects cygwin style paths, always. hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)