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

Improve handling of spaces in file paths #1705

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

craddm
Copy link
Contributor

@craddm craddm commented Jan 17, 2024

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).
  • You have marked this pull request as a draft and added '[WIP]' to the title if needed (if you're not yet ready to merge).
  • You have formatted your code using appropriate automated tools (for example ./tests/AutoFormat_Powershell.ps1 -TargetPath <path to file or directory> for Powershell).

⤴️ Summary

Replaces Invoke-Expression with the call operator &. Invoke-Expression does not handle spaces in file paths well without some additional editing of the file path.
This leads to errors on Windows systems, for example. The call operator correctly quotes the file path and avoids the issue.

🌂 Related issues

Closes #934

🔬 Tests

Tested deployments on Windows systems where spaces were present in the file path and Linux systems to ensure that new command structure functions correctly on both systems and is robust to file path formatting.

@craddm craddm changed the title Replace Invoke-Expression with call operator Improve handling of spaces in file paths Jan 17, 2024
Copy link
Member

@JimMadge JimMadge left a comment

Choose a reason for hiding this comment

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

I think there are some other Invoke-Expression calls (although, fewer than I thought 🎉)

rg Invoke-Expression
deployment/administration/SRE_Teardown.ps1
86:    Invoke-Expression -Command "$scriptPath -shmId $shmId -sreId $sreId"

deployment/administration/SRE_SRD_Remote_Diagnostics.ps1
42:Invoke-Expression -Command "$(Join-Path $PSScriptRoot '..' 'secure_research_environment' 'setup' 'Run_SRE_SRD_Remote_Diagnostics.ps1') -shmId $shmId -sreId $sreId -ipLastOctet $ipLastOctet"

deployment/secure_research_environment/setup/Apply_SRE_Network_Configuration.ps1
113:Invoke-Expression -Command "$(Join-Path $PSScriptRoot Unpeer_SRE_Package_Repositories.ps1) -shmId $shmId -sreId $sreId"
149:Invoke-Expression -Command "$(Join-Path $PSScriptRoot "Configure_External_DNS_Queries.ps1") -shmId $shmId -sreId $sreId"

Can we address those here too?

@craddm
Copy link
Contributor Author

craddm commented Jan 18, 2024

I think there are some other Invoke-Expression calls (although, fewer than I thought 🎉)

❯ rg Invoke-Expression
deployment/administration/SRE_Teardown.ps1
86:    Invoke-Expression -Command "$scriptPath -shmId $shmId -sreId $sreId"

deployment/administration/SRE_SRD_Remote_Diagnostics.ps1
42:Invoke-Expression -Command "$(Join-Path $PSScriptRoot '..' 'secure_research_environment' 'setup' 'Run_SRE_SRD_Remote_Diagnostics.ps1') -shmId $shmId -sreId $sreId -ipLastOctet $ipLastOctet"

Can we address those here too?

Hm. So it seems the first one, in SRE_Teardown.ps1, doesn't actually cause a problem. If the file path is stored in a variable, then it's correctly quoted when Invoke-Expression runs.

So we could either leave it alone, or change it for consistency with the others. Or change the others for consistency with this one.

Scratch that, it is actually broken, will fix that too

@craddm craddm merged commit 310eca1 into alan-turing-institute:develop Jan 22, 2024
11 checks passed
@craddm craddm deleted the platform-path branch February 19, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-platform path issues
2 participants