Skip to content

Commit

Permalink
Create ~/.ssh on Windows if it doesn't exist
Browse files Browse the repository at this point in the history
Beaker executed `mkdir -p "~/.ssh"` on Windows hosts as part of the prebuilt
steps sequence. However, when using cygwin bash, the double quotes behave like
single quotes, disabling tilde expansion:

   $ realpath "~/.ssh"
   /home/Administrator/~/.ssh

So '~' was a directory containing the '.ssh' directory. This was never noticed
because all of our VM templates already have the expected ~/.ssh directory. But
if the directory doesn't exist, then later steps would fail trying to write to
~/.ssh/environment.

This commit changes beaker behavior in the case that the path starts with tilde
and does not contain a space, so it's safe to not quote the path.

See commit 54b35b7 which double quoted unix &
windows, which caused a regression that was fixed in 54b35b7.
  • Loading branch information
joshcooper committed Jun 27, 2022
1 parent 6c0b15b commit c58d7d6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/beaker/host/windows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ def selinux_enabled?()
end

# Create the provided directory structure on the host
# @param [String] dir The directory structure to create on the host
# @param [String,Pathname] 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}\""
# single or double quotes will disable ~ expansion, so only quote if we have to
str = dir.to_s
cmd = if str.start_with?('~') && str !~ / /
"mkdir -p #{str}"
else
"mkdir -p \"#{str}\""
end
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
result.exit_code == 0
end
Expand Down

0 comments on commit c58d7d6

Please sign in to comment.