Skip to content

Add test to verify filesystem provider isn't used when accessing root path in psdrive - #7173

Merged
Aditya Patwardhan (adityapatwardhan) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:set-location-test
Jul 11, 2018
Merged

Aditya Patwardhan (adityapatwardhan) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:set-location-test

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Jun 25, 2018 •

Copy link
Copy Markdown
Member

PR Summary

This was an issue introduced by 7459b54.

When in a PSDrive, and you set-location to a root qualified path, it should be based on the current psdrive and not the filesystem. Exception is on non-Windows, all paths start with / so it's always treated as filesystem.

PR Checklist

@iSazonov

Copy link
Copy Markdown
Collaborator

Exception is on non-Windows, all paths start with / so it's always treated as filesystem.

Now I try dir / on SCCM provider, it returns 18 values. If the provider will be ported users can do dir /application on non-Windows.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) There's a fundamental problem with PSDrives on non-Windows and will probably become a bigger issues as more SHiPS based providers are written that are cross platform. We should discuss that here #6773

@BrucePay Bruce Payette (BrucePay) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

It "Should not use filesystem root folder if not in filesystem provider" -Skip:(!$IsWindows) {
# find filesystem root folder that doesn't exist in HKCU:
$foundFolder = $false
foreach ($folder in (Get-ChildItem "${env:SystemDrive}\" -Directory)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The parens around Get-ChildItem are unnecessary.

# find filesystem root folder that doesn't exist in HKCU:
$foundFolder = $false
foreach ($folder in (Get-ChildItem "${env:SystemDrive}\" -Directory)) {
if (!(Test-Path "HKCU:\$($folder.Name)")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the convention is to use -not instead of ! simply because it's more visible.

}
}
$foundFolder | Should -BeTrue
Set-Location HKCU:\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use Push-Location HKCU:\ in try and Pop-Location in finally to reset the current working directory.

@SteveL-MSFT Steve Lee (SteveL-MSFT) Jun 28, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is for Set-Location tests, though. There's a BeforeAll and AfterAll that sets the location back to where it was.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok. closed.

@anmenaga

Copy link
Copy Markdown

Aditya Patwardhan (@adityapatwardhan) this needs your review approval. It looks ready for merge.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Aditya Patwardhan (@adityapatwardhan) can you re-review?

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit e5e1c53 into PowerShell:master Jul 11, 2018
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the set-location-test branch October 26, 2018 21:35
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
… path in psdrive (PowerShell#7173)

* add test to verify filesystem isn't used when not in filesystem drive
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.

5 participants