diff --git a/plugins/guests/darwin/cap/shell_expand_guest_path.rb b/plugins/guests/darwin/cap/shell_expand_guest_path.rb index 1fdcf5215..3bf439ef9 100644 --- a/plugins/guests/darwin/cap/shell_expand_guest_path.rb +++ b/plugins/guests/darwin/cap/shell_expand_guest_path.rb @@ -4,7 +4,7 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf #{path}") do |type, data| + machine.communicate.execute("printf \"#{path}\"") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb index 6d2f6e16a..854a2eef8 100644 --- a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,7 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf #{path}", + machine.communicate.execute("printf \"#{path}\"", shell: "sh") do |type, data| if type == :stdout real_path ||= "" diff --git a/plugins/guests/linux/cap/shell_expand_guest_path.rb b/plugins/guests/linux/cap/shell_expand_guest_path.rb index cc32d7f7c..9065873b2 100644 --- a/plugins/guests/linux/cap/shell_expand_guest_path.rb +++ b/plugins/guests/linux/cap/shell_expand_guest_path.rb @@ -4,7 +4,7 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("echo; printf #{path}") do |type, data| + machine.communicate.execute("echo; printf \"#{path}\"") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb index 8471f4724..4dce5e2d6 100644 --- a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,7 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf #{path}") do |type, data| + machine.communicate.execute("printf \"#{path}\"") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb index 653493548..b1a82813f 100644 --- a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,7 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf #{path}") do |type, data| + machine.communicate.execute("printf \"#{path}\"") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/provisioners/file/provisioner.rb b/plugins/provisioners/file/provisioner.rb index 3c8081fce..46355c11b 100644 --- a/plugins/provisioners/file/provisioner.rb +++ b/plugins/provisioners/file/provisioner.rb @@ -18,10 +18,10 @@ module VagrantPlugins # # https://serverfault.com/questions/538368/make-scp-always-overwrite-or-create-directory # https://unix.stackexchange.com/questions/292641/get-scp-path-behave-like-rsync-path/292732 - command = "mkdir -p %s" % destination + command = "mkdir -p \"%s\"" % destination source << "/." else - command = "mkdir -p %s" % File.dirname(destination) + command = "mkdir -p \"%s\"" % File.dirname(destination) end comm.execute(command) diff --git a/test/unit/plugins/provisioners/file/provisioner_test.rb b/test/unit/plugins/provisioners/file/provisioner_test.rb index a42f1169c..8da38e6d7 100644 --- a/test/unit/plugins/provisioners/file/provisioner_test.rb +++ b/test/unit/plugins/provisioners/file/provisioner_test.rb @@ -34,7 +34,25 @@ describe VagrantPlugins::FileUpload::Provisioner do allow(config).to receive(:source).and_return("/source") allow(config).to receive(:destination).and_return("/foo/bar") - expect(communicator).to receive(:execute).with("mkdir -p /foo") + expect(communicator).to receive(:execute).with("mkdir -p \"/foo\"") + + subject.provision + end + + it "creates the destination directory with a space" do + allow(config).to receive(:source).and_return("/source") + allow(config).to receive(:destination).and_return("/foo bar/bar") + + expect(communicator).to receive(:execute).with("mkdir -p \"/foo bar\"") + + subject.provision + end + + it "creates the destination directory above file" do + allow(config).to receive(:source).and_return("/source/file.sh") + allow(config).to receive(:destination).and_return("/foo/bar/file.sh") + + expect(communicator).to receive(:execute).with("mkdir -p \"/foo/bar\"") subject.provision end