Ensure paths with spaces are preserved
Prior to this commit, if a user set the `destination` path to include a space, the `shell_expand_guest_path` function would remove that space and return a partial path. This commit updates that to quote the path to be expanded to preserve the entire path.
This commit is contained in:
parent
40eaef08b7
commit
61c501cc65
|
@ -4,7 +4,7 @@ module VagrantPlugins
|
||||||
class ShellExpandGuestPath
|
class ShellExpandGuestPath
|
||||||
def self.shell_expand_guest_path(machine, path)
|
def self.shell_expand_guest_path(machine, path)
|
||||||
real_path = nil
|
real_path = nil
|
||||||
machine.communicate.execute("printf #{path}") do |type, data|
|
machine.communicate.execute("printf \"#{path}\"") do |type, data|
|
||||||
if type == :stdout
|
if type == :stdout
|
||||||
real_path ||= ""
|
real_path ||= ""
|
||||||
real_path += data
|
real_path += data
|
||||||
|
|
|
@ -4,7 +4,7 @@ module VagrantPlugins
|
||||||
class ShellExpandGuestPath
|
class ShellExpandGuestPath
|
||||||
def self.shell_expand_guest_path(machine, path)
|
def self.shell_expand_guest_path(machine, path)
|
||||||
real_path = nil
|
real_path = nil
|
||||||
machine.communicate.execute("printf #{path}",
|
machine.communicate.execute("printf \"#{path}\"",
|
||||||
shell: "sh") do |type, data|
|
shell: "sh") do |type, data|
|
||||||
if type == :stdout
|
if type == :stdout
|
||||||
real_path ||= ""
|
real_path ||= ""
|
||||||
|
|
|
@ -4,7 +4,7 @@ module VagrantPlugins
|
||||||
class ShellExpandGuestPath
|
class ShellExpandGuestPath
|
||||||
def self.shell_expand_guest_path(machine, path)
|
def self.shell_expand_guest_path(machine, path)
|
||||||
real_path = nil
|
real_path = nil
|
||||||
machine.communicate.execute("echo; printf #{path}") do |type, data|
|
machine.communicate.execute("echo; printf \"#{path}\"") do |type, data|
|
||||||
if type == :stdout
|
if type == :stdout
|
||||||
real_path ||= ""
|
real_path ||= ""
|
||||||
real_path += data
|
real_path += data
|
||||||
|
|
|
@ -4,7 +4,7 @@ module VagrantPlugins
|
||||||
class ShellExpandGuestPath
|
class ShellExpandGuestPath
|
||||||
def self.shell_expand_guest_path(machine, path)
|
def self.shell_expand_guest_path(machine, path)
|
||||||
real_path = nil
|
real_path = nil
|
||||||
machine.communicate.execute("printf #{path}") do |type, data|
|
machine.communicate.execute("printf \"#{path}\"") do |type, data|
|
||||||
if type == :stdout
|
if type == :stdout
|
||||||
real_path ||= ""
|
real_path ||= ""
|
||||||
real_path += data
|
real_path += data
|
||||||
|
|
|
@ -4,7 +4,7 @@ module VagrantPlugins
|
||||||
class ShellExpandGuestPath
|
class ShellExpandGuestPath
|
||||||
def self.shell_expand_guest_path(machine, path)
|
def self.shell_expand_guest_path(machine, path)
|
||||||
real_path = nil
|
real_path = nil
|
||||||
machine.communicate.execute("printf #{path}") do |type, data|
|
machine.communicate.execute("printf \"#{path}\"") do |type, data|
|
||||||
if type == :stdout
|
if type == :stdout
|
||||||
real_path ||= ""
|
real_path ||= ""
|
||||||
real_path += data
|
real_path += data
|
||||||
|
|
|
@ -18,10 +18,10 @@ module VagrantPlugins
|
||||||
#
|
#
|
||||||
# https://serverfault.com/questions/538368/make-scp-always-overwrite-or-create-directory
|
# 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
|
# 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 << "/."
|
source << "/."
|
||||||
else
|
else
|
||||||
command = "mkdir -p %s" % File.dirname(destination)
|
command = "mkdir -p \"%s\"" % File.dirname(destination)
|
||||||
end
|
end
|
||||||
comm.execute(command)
|
comm.execute(command)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,25 @@ describe VagrantPlugins::FileUpload::Provisioner do
|
||||||
allow(config).to receive(:source).and_return("/source")
|
allow(config).to receive(:source).and_return("/source")
|
||||||
allow(config).to receive(:destination).and_return("/foo/bar")
|
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
|
subject.provision
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue