folders/rsync: Shellescape guest paths

This allows users to have spaces or other special characters in
destination paths on the guest.
This commit is contained in:
Seth Vargo 2016-07-13 10:02:09 -06:00
parent 1c0d0b8b9d
commit 7f1947fec2
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 12 additions and 4 deletions

View File

@ -1,3 +1,5 @@
require "shellwords"
module VagrantPlugins module VagrantPlugins
module GuestLinux module GuestLinux
module Cap module Cap
@ -11,9 +13,8 @@ module VagrantPlugins
end end
def self.rsync_pre(machine, opts) def self.rsync_pre(machine, opts)
machine.communicate.tap do |comm| guest_path = Shellwords.escape(opts[:guestpath])
comm.sudo("mkdir -p '#{opts[:guestpath]}'") machine.communicate.sudo("mkdir -p #{guest_path}")
end
end end
def self.rsync_post(machine, opts) def self.rsync_post(machine, opts)
@ -21,8 +22,10 @@ module VagrantPlugins
return return
end end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo( machine.communicate.sudo(
"find '#{opts[:guestpath]}' " + "find #{guest_path} " +
"'!' -type l -a " + "'!' -type l -a " +
"'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " + "'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"xargs -0 -r chown #{opts[:owner]}:#{opts[:group]}") "xargs -0 -r chown #{opts[:owner]}:#{opts[:group]}")

View File

@ -1,3 +1,5 @@
require "shellwords"
require "vagrant/util/platform" require "vagrant/util/platform"
require "vagrant/util/subprocess" require "vagrant/util/subprocess"
@ -43,6 +45,9 @@ module VagrantPlugins
guestpath = machine.guest.capability(:rsync_scrub_guestpath, opts) guestpath = machine.guest.capability(:rsync_scrub_guestpath, opts)
end end
# Shellescape
guestpath = Shellwords.escape(guestpath)
if Vagrant::Util::Platform.windows? if Vagrant::Util::Platform.windows?
# rsync for Windows expects cygwin style paths, always. # rsync for Windows expects cygwin style paths, always.
hostpath = Vagrant::Util::Platform.cygwin_path(hostpath) hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)