diff --git a/plugins/guests/solaris11/cap/shell_expand_guest_path.rb b/plugins/guests/solaris11/cap/shell_expand_guest_path.rb new file mode 100644 index 000000000..167b0f61a --- /dev/null +++ b/plugins/guests/solaris11/cap/shell_expand_guest_path.rb @@ -0,0 +1,32 @@ +module VagrantPlugins + module GuestSolaris11 + module Cap + class ShellExpandGuestPath + def self.shell_expand_guest_path(machine, path) + real_path = nil + path = path.gsub(/ /, '\ ') + machine.communicate.execute("echo; printf #{path}") do |type, data| + if type == :stdout + real_path ||= "" + real_path += data + end + end + + if real_path + # The last line is the path we care about + real_path = real_path.split("\n").last.chomp + end + + if !real_path + # If no real guest path was detected, this is really strange + # and we raise an exception because this is a bug. + raise Vagrant::Errors::ShellExpandFailed + end + + # Chomp the string so that any trailing newlines are killed + return real_path.chomp + end + end + end + end +end diff --git a/plugins/guests/solaris11/plugin.rb b/plugins/guests/solaris11/plugin.rb index 768f70f4e..559b9530c 100644 --- a/plugins/guests/solaris11/plugin.rb +++ b/plugins/guests/solaris11/plugin.rb @@ -29,6 +29,11 @@ module VagrantPlugins require_relative "cap/configure_networks" Cap::ConfigureNetworks end + + guest_capability(:solaris11, :shell_expand_guest_path) do + require_relative "cap/shell_expand_guest_path" + Cap::ShellExpandGuestPath + end end end end diff --git a/test/unit/plugins/guests/solaris11/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/solaris11/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..d117c9173 --- /dev/null +++ b/test/unit/plugins/guests/solaris11/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,52 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestSolaris11::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestSolaris11::Plugin + .components + .guest_capabilities[:solaris11] + end + + let(:machine) { double("machine", config: double("config", solaris11: double("solaris11", suexec_cmd: 'sudo', device: 'net'))) } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/export/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/export/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "expands a path with tilde" do + path = "~/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/export/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/export/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/export/home/vagrant folder/folder" + path_with_spaces = "/export/home/vagrant\\ folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, path_with_spaces) + + expect(machine.communicate).to receive(:execute).with("printf #{path_with_spaces}") + cap.shell_expand_guest_path(machine, path) + end + end +end