Switch to PowerShell for create_remote_directory
This commit is contained in:
parent
3b5443a5e7
commit
fcd07e3a37
@ -35,9 +35,12 @@ module VagrantPlugins
|
||||
|
||||
if force_raw
|
||||
if shell == "powershell"
|
||||
base_cmd = "powershell \"Write-Host #{CMD_GARBAGE_MARKER}; [Console]::Error.WriteLine('#{CMD_GARBAGE_MARKER}'); #{command}\""
|
||||
command = "Write-Host #{CMD_GARBAGE_MARKER}; [Console]::Error.WriteLine('#{CMD_GARBAGE_MARKER}'); #{command}"
|
||||
command = Base64.strict_encode64(command.encode("UTF-16LE", "UTF-8"))
|
||||
base_cmd = "powershell -encodedCommand #{command}"
|
||||
else
|
||||
base_cmd = "cmd /q /c \"ECHO #{CMD_GARBAGE_MARKER} && ECHO #{CMD_GARBAGE_MARKER} 1>&2 && #{command}\""
|
||||
command = "ECHO #{CMD_GARBAGE_MARKER} && ECHO #{CMD_GARBAGE_MARKER} 1>&2 && #{command}"
|
||||
base_cmd = "cmd /q /c \"#{command}\""
|
||||
end
|
||||
else
|
||||
tfile = Tempfile.new('vagrant-ssh')
|
||||
@ -227,7 +230,7 @@ SCRIPT
|
||||
end
|
||||
|
||||
def create_remote_directory(dir, force_raw=false)
|
||||
execute("if not exist \"#{dir}\" mkdir \"#{dir}\"", shell: "cmd", force_raw: force_raw)
|
||||
execute("md -Force \"#{dir}\"", shell: "powershell", force_raw: force_raw)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -17,12 +17,14 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
|
||||
)
|
||||
end
|
||||
|
||||
let(:shell) { "cmd" }
|
||||
|
||||
# SSH configuration information mock
|
||||
let(:winssh) do
|
||||
double("winssh",
|
||||
insert_key: false,
|
||||
export_command_template: export_command_template,
|
||||
shell: 'cmd',
|
||||
shell: shell,
|
||||
upload_directory: "C:\\Windows\\Temp"
|
||||
)
|
||||
end
|
||||
@ -225,6 +227,22 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
|
||||
with(/ECHO #{command_garbage_marker} && ECHO #{command_garbage_marker}.*/)
|
||||
expect(communicator.execute("dir", force_raw: true)).to eq(0)
|
||||
end
|
||||
|
||||
context "and shell is powershell" do
|
||||
let(:shell) { "powershell" }
|
||||
|
||||
it "passes the correct flags to powershell" do
|
||||
expect(channel).to receive(:exec).
|
||||
with(/-encodedCommand/)
|
||||
expect(communicator.execute("dir", force_raw: true)).to eq(0)
|
||||
end
|
||||
|
||||
it "encodes the raw command" do
|
||||
expect(channel).to receive(:exec).
|
||||
with(/VwByAGkAdABlAC0ASABvAHMAdAAgADQAMQBlADUANwBkADMAOAAtAGIANABmADcALQA0AGUANAA2AC0AOQBjADMAOAAtADEAMwA4ADcAMwBkADMAMwA4AGIAOAA2AC0AdgBhAGcAcgBhAG4AdAAtAHMAcwBoADsAIABbAEMAbwBuAHMAbwBsAGUAXQA6ADoARQByAHIAbwByAC4AVwByAGkAdABlAEwAaQBuAGUAKAAnADQAMQBlADUANwBkADMAOAAtAGIANABmADcALQA0AGUANAA2AC0AOQBjADMAOAAtADEAMwA4ADcAMwBkADMAMwA4AGIAOAA2AC0AdgBhAGcAcgBhAG4AdAAtAHMAcwBoACcAKQA7ACAAZABpAHIA/)
|
||||
expect(communicator.execute("dir", force_raw: true)).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -550,4 +568,20 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create_remote_directory" do
|
||||
it "should set the shell to powershell" do
|
||||
expect(communicator).to receive(:execute).with(
|
||||
anything,
|
||||
hash_including(shell: "powershell"))
|
||||
communicator.create_remote_directory('c:\destination')
|
||||
end
|
||||
|
||||
it "should use an appropriate command for powershell" do
|
||||
expect(communicator).to receive(:execute).with(
|
||||
/md -Force/,
|
||||
anything)
|
||||
communicator.create_remote_directory('c:\destination')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user