Update rm filters to test for path
This commit updates the rm filter for winrm to operate like how rm works in bash. If a folder doesn't exist, the command returns 0 rather than 1.
This commit is contained in:
parent
c882d888a7
commit
93356d4635
|
@ -31,9 +31,9 @@ module VagrantPlugins
|
||||||
|
|
||||||
ret_cmd = ''
|
ret_cmd = ''
|
||||||
if recurse
|
if recurse
|
||||||
ret_cmd = "rm \"#{dir}\" -recurse -force"
|
ret_cmd = "if (Test-Path \"#{dir}\") {Remove-Item \"#{dir}\" -force -recurse}"
|
||||||
else
|
else
|
||||||
ret_cmd = "if (Test-Path #{dir}) {Remove-Item #{dir} -force}"
|
ret_cmd = "if (Test-Path \"#{dir}\") {Remove-Item \"#{dir}\" -force}"
|
||||||
end
|
end
|
||||||
return ret_cmd
|
return ret_cmd
|
||||||
end
|
end
|
||||||
|
|
|
@ -127,10 +127,8 @@ module VagrantPlugins
|
||||||
def create_container(config)
|
def create_container(config)
|
||||||
args = container_run_args(config)
|
args = container_run_args(config)
|
||||||
|
|
||||||
@machine.communicate.sudo %[rm -f #{config[:cidfile]}
|
@machine.communicate.sudo %[rm -f "#{config[:cidfile]}"]
|
||||||
]
|
@machine.communicate.sudo %[docker run #{args}]
|
||||||
@machine.communicate.sudo %[docker run #{args}
|
|
||||||
]
|
|
||||||
|
|
||||||
sha = Digest::SHA1.hexdigest(args)
|
sha = Digest::SHA1.hexdigest(args)
|
||||||
container_data_path(config).open("w+") do |f|
|
container_data_path(config).open("w+") do |f|
|
||||||
|
|
|
@ -54,20 +54,22 @@ describe VagrantPlugins::CommunicatorWinRM::CommandFilter, unit: true do
|
||||||
|
|
||||||
it 'filters out rm recurse commands' do
|
it 'filters out rm recurse commands' do
|
||||||
expect(subject.filter('rm -Rf /some/dir')).to eq(
|
expect(subject.filter('rm -Rf /some/dir')).to eq(
|
||||||
"rm \"/some/dir\" -recurse -force")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force -recurse}")
|
||||||
expect(subject.filter('rm -fr /some/dir')).to eq(
|
expect(subject.filter('rm -fr /some/dir')).to eq(
|
||||||
"rm \"/some/dir\" -recurse -force")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force -recurse}")
|
||||||
expect(subject.filter('rm -r /some/dir')).to eq(
|
expect(subject.filter('rm -r /some/dir')).to eq(
|
||||||
"rm \"/some/dir\" -recurse -force")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force -recurse}")
|
||||||
expect(subject.filter('rm -r "/some/dir"')).to eq(
|
expect(subject.filter('rm -r "/some/dir"')).to eq(
|
||||||
"rm \"/some/dir\" -recurse -force")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force -recurse}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters out rm commands' do
|
it 'filters out rm commands' do
|
||||||
expect(subject.filter('rm /some/dir')).to eq(
|
expect(subject.filter('rm /some/dir')).to eq(
|
||||||
"if (Test-Path /some/dir) {Remove-Item /some/dir -force}")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force}")
|
||||||
expect(subject.filter('rm -f /some/dir')).to eq(
|
expect(subject.filter('rm -f /some/dir')).to eq(
|
||||||
"if (Test-Path /some/dir) {Remove-Item /some/dir -force}")
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force}")
|
||||||
|
expect(subject.filter('rm -f "/some/dir"')).to eq(
|
||||||
|
"if (Test-Path \"/some/dir\") {Remove-Item \"/some/dir\" -force}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters out mkdir commands' do
|
it 'filters out mkdir commands' do
|
||||||
|
|
Loading…
Reference in New Issue