diff --git a/plugins/synced_folders/rsync/default_unix_cap.rb b/plugins/synced_folders/rsync/default_unix_cap.rb index 6e073fde5..dcf4b5a34 100644 --- a/plugins/synced_folders/rsync/default_unix_cap.rb +++ b/plugins/synced_folders/rsync/default_unix_cap.rb @@ -32,7 +32,7 @@ module VagrantPlugins exclude_base = Pathname.new(opts[:guestpath]) exclusions = Array(opts[:exclude]).map do |ex_path| ex_path = ex_path.slice(1, ex_path.size) if ex_path.start_with?(File::SEPARATOR) - "-path #{exclude_base.join(ex_path)} -prune" + "-path #{Shellwords.escape(exclude_base.join(ex_path))} -prune" end.join(" -o ") + " -o " end "find #{guest_path} #{exclusions}" \ diff --git a/test/unit/plugins/guests/linux/cap/rsync_test.rb b/test/unit/plugins/guests/linux/cap/rsync_test.rb index 4676cdf04..01f4e6156 100644 --- a/test/unit/plugins/guests/linux/cap/rsync_test.rb +++ b/test/unit/plugins/guests/linux/cap/rsync_test.rb @@ -70,15 +70,27 @@ describe "VagrantPlugins::GuestLinux::Cap::Rsync" do end context "with excludes provided" do - let(:excludes){ ["tmp", "state/*"] } + let(:excludes){ ["tmp", "state/*", "path/with a/space"] } it "ignores files that are excluded" do - comm.expect_command( - "find #{guest_directory} -path #{File.join(guest_directory, excludes.first)} -prune -o " \ - "-path #{File.join(guest_directory, excludes.last)} -prune -o '!' -type l -a '(' ! -user " \ - "#{owner} -or ! -group #{group} ')' -exec chown #{owner}:#{group} '{}' +" - ) + # comm.expect_command( + # "find #{guest_directory} -path #{Shellwords.escape(File.join(guest_directory, excludes.first))} -prune -o " \ + # "-path #{Shellwords.escape(File.join(guest_directory, excludes.last))} -prune -o '!' " \ + # "-path -type l -a '(' ! -user " \ + # "#{owner} -or ! -group #{group} ')' -exec chown #{owner}:#{group} '{}' +" + # ) cap.rsync_post(machine, options) + excludes.each do |ex_path| + expect(comm.received_commands.first).to include("-path #{Shellwords.escape(File.join(guest_directory, ex_path))} -prune") + end + end + + it "properly escapes excluded directories" do + cap.rsync_post(machine, options) + exclude_with_space = excludes.detect{|ex| ex.include?(' ')} + escaped_exclude_with_space = Shellwords.escape(exclude_with_space) + expect(comm.received_commands.first).not_to include(exclude_with_space) + expect(comm.received_commands.first).to include(escaped_exclude_with_space) end end end