Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) quote file path in file_contents_on and file_exists_on #1647

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/beaker/dsl/helpers/host_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ def win_ads_path(file_path)
# @return [Boolean] Whether the file exists on the host (using `test -f`)
def file_exists_on(host, file_path)
if host['platform'] =~ /windows/
command = %(Test-Path #{file_path})
command = %(Test-Path "#{file_path}")

if file_path.include?(':')
split_path = win_ads_path(file_path)

command = %(Test-Path #{split_path[:path]})
command = %(Test-Path "#{split_path[:path]}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to support paths with spaces in them?
I think you would need it here too and on line 495 above for the case where there is no ads path?

https://github.com/puppetlabs/beaker/pull/1647/files#diff-cdd2e965e7b543eb19634118d43851b8R495

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to protect windows path (c:\asdasd) from cygwin shell expansion. Without it C:\Windows\TEMP\install-puppet-2020-05-15_15.38.14.log gets modified to C:\cygwin64\home\Administrator\WindowsTEMPinstall-puppet-2020-05-15_15.38.14.log

command += %( -AND Get-Item -path #{split_path[:path]} -stream #{split_path[:ads]}) if split_path[:ads]
end

Expand Down Expand Up @@ -555,8 +555,8 @@ def file_contents_on(host, file_path)
if host['platform'] =~ /windows/
file_path.gsub!('/', '\\')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that substitution is not done in file_exists_on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to work without, should I still add it there?


command = %{Get-Content -Raw -Path #{file_path}}
command += %{ -Stream #{split_path[:ads]}} if split_path[:ads]
command = %{Get-Content -Raw -Path "#{file_path}"}
command += %{ -Stream "#{split_path[:ads]}"} if split_path[:ads]

file_contents = on(host, powershell(command))&.stdout&.strip
else
Expand Down