Merge pull request #7928 from chrisroberts/rsync/exclude-paths

synced_folders/rsync: Quote exclude paths
This commit is contained in:
Chris Roberts 2016-10-26 07:16:15 -07:00 committed by GitHub
commit dd7294b021
2 changed files with 19 additions and 7 deletions

View File

@ -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}" \

View File

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