From 7f1947fec26400792ac7860e079d2e9e7d5e98ff Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 13 Jul 2016 10:02:09 -0600 Subject: [PATCH] folders/rsync: Shellescape guest paths This allows users to have spaces or other special characters in destination paths on the guest. --- plugins/guests/linux/cap/rsync.rb | 11 +++++++---- plugins/synced_folders/rsync/helper.rb | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/guests/linux/cap/rsync.rb b/plugins/guests/linux/cap/rsync.rb index 424d20f46..bd3d6f9b1 100644 --- a/plugins/guests/linux/cap/rsync.rb +++ b/plugins/guests/linux/cap/rsync.rb @@ -1,3 +1,5 @@ +require "shellwords" + module VagrantPlugins module GuestLinux module Cap @@ -11,9 +13,8 @@ module VagrantPlugins end def self.rsync_pre(machine, opts) - machine.communicate.tap do |comm| - comm.sudo("mkdir -p '#{opts[:guestpath]}'") - end + guest_path = Shellwords.escape(opts[:guestpath]) + machine.communicate.sudo("mkdir -p #{guest_path}") end def self.rsync_post(machine, opts) @@ -21,8 +22,10 @@ module VagrantPlugins return end + guest_path = Shellwords.escape(opts[:guestpath]) + machine.communicate.sudo( - "find '#{opts[:guestpath]}' " + + "find #{guest_path} " + "'!' -type l -a " + "'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " + "xargs -0 -r chown #{opts[:owner]}:#{opts[:group]}") diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index aa6cb710b..46d7643c5 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -1,3 +1,5 @@ +require "shellwords" + require "vagrant/util/platform" require "vagrant/util/subprocess" @@ -43,6 +45,9 @@ module VagrantPlugins guestpath = machine.guest.capability(:rsync_scrub_guestpath, opts) end + # Shellescape + guestpath = Shellwords.escape(guestpath) + if Vagrant::Util::Platform.windows? # rsync for Windows expects cygwin style paths, always. hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)