synced_folders/rsync: Escape exclude paths
This commit is contained in:
parent
88d094505b
commit
05c5aab92a
|
@ -32,7 +32,7 @@ module VagrantPlugins
|
||||||
exclude_base = Pathname.new(opts[:guestpath])
|
exclude_base = Pathname.new(opts[:guestpath])
|
||||||
exclusions = Array(opts[:exclude]).map do |ex_path|
|
exclusions = Array(opts[:exclude]).map do |ex_path|
|
||||||
ex_path = ex_path.slice(1, ex_path.size) if ex_path.start_with?(File::SEPARATOR)
|
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.join(" -o ") + " -o "
|
||||||
end
|
end
|
||||||
"find #{guest_path} #{exclusions}" \
|
"find #{guest_path} #{exclusions}" \
|
||||||
|
|
|
@ -70,15 +70,27 @@ describe "VagrantPlugins::GuestLinux::Cap::Rsync" do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with excludes provided" do
|
context "with excludes provided" do
|
||||||
let(:excludes){ ["tmp", "state/*"] }
|
let(:excludes){ ["tmp", "state/*", "path/with a/space"] }
|
||||||
|
|
||||||
it "ignores files that are excluded" do
|
it "ignores files that are excluded" do
|
||||||
comm.expect_command(
|
# comm.expect_command(
|
||||||
"find #{guest_directory} -path #{File.join(guest_directory, excludes.first)} -prune -o " \
|
# "find #{guest_directory} -path #{Shellwords.escape(File.join(guest_directory, excludes.first))} -prune -o " \
|
||||||
"-path #{File.join(guest_directory, excludes.last)} -prune -o '!' -type l -a '(' ! -user " \
|
# "-path #{Shellwords.escape(File.join(guest_directory, excludes.last))} -prune -o '!' " \
|
||||||
"#{owner} -or ! -group #{group} ')' -exec chown #{owner}:#{group} '{}' +"
|
# "-path -type l -a '(' ! -user " \
|
||||||
)
|
# "#{owner} -or ! -group #{group} ')' -exec chown #{owner}:#{group} '{}' +"
|
||||||
|
# )
|
||||||
cap.rsync_post(machine, options)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue