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

Conversation

ciprianbadescu
Copy link
Contributor

No description provided.

@ciprianbadescu ciprianbadescu requested a review from a team as a code owner May 15, 2020 12:57
@ciprianbadescu ciprianbadescu requested a review from a team May 15, 2020 12:57
@@ -497,7 +497,7 @@ def file_exists_on(host, 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

@@ -555,7 +555,7 @@ 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?

@@ -555,7 +555,7 @@ def file_contents_on(host, file_path)
if host['platform'] =~ /windows/
file_path.gsub!('/', '\\')

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

Choose a reason for hiding this comment

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

would you need it here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this change is surely needed

@ciprianbadescu
Copy link
Contributor Author

To give more background, puppet-code acceptance failed with bellow error. It looks that if the "c:\" path is passed as parameter from directly from cygwin to powershell without " it gets messed up.

I updated in this PR the two cases hit by my tests (while I still think file_exists_on is not really working, as it never fails, with or without the change)

    naval-racetrack.delivery.puppetlabs.net (windows2012r2-64-1) 15:38:23$ powershell.exe -ExecutionPolicy Bypass -InputFormat None -NoLogo -NoProfile -NonInteractive -Command Test-Path C:\Windows\TEMP\install-puppet-2020-05-15_15.38.14.log
      False
    
    naval-racetrack.delivery.puppetlabs.net (windows2012r2-64-1) executed in 0.92 seconds
    
    naval-racetrack.delivery.puppetlabs.net (windows2012r2-64-1) 15:38:24$ powershell.exe -ExecutionPolicy Bypass -InputFormat None -NoLogo -NoProfile -NonInteractive -Command Get-Content -Raw -Path C:\Windows\TEMP\install-puppet-2020-05-15_15.38.14.log
      Get-Content : Cannot find path 'C:\cygwin64\home\Administrator\WindowsTEMPinsta
      ll-puppet-2020-05-15_15.38.14.log' because it does not exist.
      At line:1 char:1
      + Get-Content -Raw -Path C:WindowsTEMPinstall-puppet-2020-05-15_15.38.14.log
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (C:\cygwin64\hom...15_15.38.14.l 
         og:String) [Get-Content], ItemNotFoundException
          + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCo 
         ntentCommand
       

@ciprianbadescu ciprianbadescu force-pushed the maint/fix-log-file-checks-on-windows branch from 7fadd8f to 87dad4d Compare May 18, 2020 06:44
@donoghuc
Copy link
Contributor

This looks very similar to #1626 (comment) are you using a beaker-puppet with this change puppetlabs/beaker-puppet#135

@ciprianbadescu
Copy link
Contributor Author

@donoghuc , I will recheck as the PR you mention was not merged/released at that time.

@ciprianbadescu
Copy link
Contributor Author

Problem is already solved in beaker 4.23.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants