Skip to content

Commit

Permalink
Merge pull request #1642 from highb/hotfix-remove-single-quoting-arou…
Browse files Browse the repository at this point in the history
…nd-file-operations-in-exec

(hotfix) Remove single quotes from Unix host file ops
  • Loading branch information
rooneyshuman committed May 8, 2020
2 parents 83ae233 + 6a9495b commit 1090023
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/beaker/host/unix/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def get_ip
# @param [String] dir The directory structure to create on the host
# @return [Boolean] True, if directory construction succeeded, otherwise False
def mkdir_p dir
cmd = "mkdir -p '#{dir}'"
cmd = "mkdir -p #{dir}"
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
result.exit_code == 0
end

# Recursively remove the path provided
# @param [String] path The path to remove
def rm_rf path
execute("rm -rf '#{path}'")
execute("rm -rf #{path}")
end

# Move the origin to destination. The destination is removed prior to moving.
Expand All @@ -144,7 +144,7 @@ def rm_rf path
# @param [Boolean] rm Remove the destination prior to move
def mv orig, dest, rm=true
rm_rf dest unless !rm
execute("mv '#{orig}' '#{dest}'")
execute("mv #{orig} #{dest}")
end

# Attempt to ping the provided target hostname
Expand Down
8 changes: 4 additions & 4 deletions spec/beaker/host/unix/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def to_s

it "deletes" do
path = '/path/to/delete'
expect( instance ).to receive(:execute).with("rm -rf '#{path}'").and_return(0)
expect( instance ).to receive(:execute).with("rm -rf #{path}").and_return(0)
expect( instance.rm_rf(path) ).to be === 0
end
end
Expand All @@ -39,14 +39,14 @@ def to_s
let(:destination) { '/destination/path/of/content' }

it 'rm first' do
expect( instance ).to receive(:execute).with("rm -rf '#{destination}'").and_return(0)
expect( instance ).to receive(:execute).with("mv '#{origin}' '#{destination}'").and_return(0)
expect( instance ).to receive(:execute).with("rm -rf #{destination}").and_return(0)
expect( instance ).to receive(:execute).with("mv #{origin} #{destination}").and_return(0)
expect( instance.mv(origin, destination) ).to be === 0

end

it 'does not rm' do
expect( instance ).to receive(:execute).with("mv '#{origin}' '#{destination}'").and_return(0)
expect( instance ).to receive(:execute).with("mv #{origin} #{destination}").and_return(0)
expect( instance.mv(origin, destination, false) ).to be === 0
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/beaker/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ module Beaker
allow( result ).to receive( :exit_code ).and_return( 0 )
allow( host ).to receive( :exec ).and_return( result )

expect( Beaker::Command ).to receive(:new).with("mkdir -p 'test/test/test'")
expect( Beaker::Command ).to receive(:new).with("mkdir -p test/test/test")
expect( host.mkdir_p('test/test/test') ).to be == true

end
Expand All @@ -337,7 +337,7 @@ module Beaker
allow( result ).to receive( :exit_code ).and_return( 0 )
allow( host ).to receive( :exec ).and_return( result )

expect( Beaker::Command ).to receive(:new).with("mkdir -p 'test/test/test'")
expect( Beaker::Command ).to receive(:new).with("mkdir -p test/test/test")
expect( host.mkdir_p('test/test/test') ).to be == true

end
Expand Down

0 comments on commit 1090023

Please sign in to comment.