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

Get-ChildItem -path '/' breaks -exclude or -include parameters #15497

Open
tsmarvin opened this issue Jun 1, 2021 · 4 comments
Open

Get-ChildItem -path '/' breaks -exclude or -include parameters #15497

tsmarvin opened this issue Jun 1, 2021 · 4 comments
Labels
Area-FileSystem-Provider specific to the FileSystem provider Issue-Bug Issue has been identified as a bug in the product Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Comments

@tsmarvin
Copy link

tsmarvin commented Jun 1, 2021

I believe there is a bug with Get-ChildItem for pwsh v7.1.3 on Ubuntu 20.04 (WSL2) when using the -exclude and -include parameters in conjunction with the -Path '/' parameter/argument combo.

This seems primarily be limited to Get-ChildItem -Path '/' as both -LiteralPath '/' and -PSPath (Get-Item -Path '/').PSPath return the data as expected when used with either -exclude or -include.

Additionally using -exclude and -path together works for directories outside /. However, I believe there may be another bug when using -Path and -Include other places as well.

Steps to reproduce

Get-ChildItem -Path '/' -Exclude 'mnt'

# Bad:
Get-ChildItem -Path '/' -Exclude 'mnt'

# Aligns with expected behavior:
Get-ChildItem -Path '/mnt' -Exclude 'c'
Get-ChildItem -LiteralPath '/' -Exclude 'mnt'
Get-ChildItem -PSPath (Get-Item -Path '/').PSPath -Exclude 'mnt'

image

Get-ChildItem -Path '/' -Include 'mnt'

# Bad:
Get-ChildItem -Path '/' -Include 'mnt' # Produces error
Get-ChildItem -Path '/mnt' -Include 'c' # Produces no output when output is expected.

# Aligns with expected behavior:
Get-ChildItem -LiteralPath '/' -Include 'mnt'
Get-ChildItem -LiteralPath '/mnt' -Include 'c'
Get-ChildItem -PSPath (Get-Item -Path '/').PSPath -Include 'mnt'
Get-ChildItem -PSPath (Get-Item -Path '/mnt').PSPath -Include 'c'

image

I'm unsure if the behavior of -Include deserves its own bug report but would be happy to split it up if needed.

Environment data

image

StackTrace:
   at Microsoft.PowerShell.Commands.FileSystemProvider.GetChildName(String path) in /PowerShell/src/System.Management.Automation/namespaces/FileSystemProvider.cs:line 5683
   at System.Management.Automation.Provider.NavigationCmdletProvider.GetChildName(String path, CmdletProviderContext context) in /PowerShell/src/System.Management.Automation/namespaces/NavigationProviderBase.cs:line 174
   at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context) in /PowerShell/src/System.Management.Automation/namespaces/LocationGlobber.cs:line 2763
   at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance) in /PowerShell/src/System.Management.Automation/namespaces/LocationGlobber.cs:line 516
   at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance) in /PowerShell/src/System.Management.Automation/namespaces/LocationGlobber.cs:line 218
   at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance) in /PowerShell/src/System.Management.Automation/namespaces/LocationGlobber.cs:line 779
   at System.Management.Automation.SessionStateInternal.GetChildItems(String path, Boolean recurse, UInt32 depth, CmdletProviderContext context) in /PowerShell/src/System.Management.Automation/engine/SessionStateContainer.cs:line 1393
   at System.Management.Automation.ChildItemCmdletProviderIntrinsics.Get(String path, Boolean recurse, UInt32 depth, CmdletProviderContext context) in /PowerShell/src/System.Management.Automation/engine/ChildrenCmdletProviderInterfaces.cs:line 278
   at Microsoft.PowerShell.Commands.GetChildItemCommand.ProcessRecord() in /PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs:line 318
   at System.Management.Automation.Cmdlet.DoProcessRecord() in /PowerShell/src/System.Management.Automation/engine/cmdlet.cs:line 173
   at System.Management.Automation.CommandProcessor.ProcessRecord() in /PowerShell/src/System.Management.Automation/engine/CommandProcessor.cs:line 388
@tsmarvin tsmarvin added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 1, 2021
@iSazonov
Copy link
Collaborator

iSazonov commented Jun 1, 2021

I guess it is dup #3304

@iSazonov iSazonov added the WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. label Jun 1, 2021
@ninmonkey
Copy link

ninmonkey commented Jun 1, 2021

@tsmarvin What do you get running these?

> Resolve-Path /

# and
> set-location -LiteralPath '/'
> Get-ChildItem -path '/'

Maybe it's related to to windows root paths. The syntax c: refers to the current directory, not the root directory.

Output

current path: D:\test

PathParam FullName
. D:\test\image.png
c: C:\Temp\export.tsv
c:\ C:\a.log
d: D:\test\image.png
d:\ D:\stuff.md

To reproduce

# Ensure both drives have a non-root `cwd` set before testing
Set-Location -Path C:\Temp\
Set-Location -Path D:\test\

'current path: '
Set-Location cd 'D:\test\'
Get-Item . | ForEach-Object FullName

$paths = '.', 'c:', 'c:\', 'd:','d:\'
$paths | ForEach-Object {
    $p = Get-ChildItem -File -Path $_ | Select-Object -First 1 | ForEach-Object FullName
    [pscustomobject]@{
       'PathParam' = $_
       'FullName' = $p
    }
}

@tsmarvin
Copy link
Author

tsmarvin commented Jun 6, 2021

Apologies - its been a busy week and I haven't had time to get back to this until now.

@ninmonkey The behavior seems to be consistent between both windows and linux. The main difference is that linux returns an error for Get-ChildItem -Path '/' -exclude 'mnt' but windows does not.

Windows:
image

Linux:
image

@iSazonov I'm unsure if this issue is the same as #3304 as the exclude/include behavior for this issue is inconsistent between the root directories and non-root directories but 3304 seems to be more about the implicit wildcard for include/exclude.
Also - for this particular issue Linux now throws an error where Windows does not.

@iSazonov iSazonov added Area-FileSystem-Provider specific to the FileSystem provider WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module Issue-Bug Issue has been identified as a bug in the product labels Nov 30, 2021
@mklement0
Copy link
Contributor

@iSazonov, it isn't a duplicate of #3304, but the workaround for the latter works here too:

# Note the "*"
Get-Item -Path /* -Exclude mnt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FileSystem-Provider specific to the FileSystem provider Issue-Bug Issue has been identified as a bug in the product Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Projects
None yet
Development

No branches or pull requests

4 participants