Skip to content

On Windows, FileSystemProvider's implementation of ItemExists does not work with long paths. #3891

Description

@jeffbi

On Windows, the overridden method ItemExists in FileSystemProvider does not properly handle paths with lengths in excess of MAX_PATH (260) characters. This adversely affects several cmdlets, including Test-Path, Set-Location, and Remove-Item, as well as TAB expansion.

Steps to reproduce

PS C:\Temp\longish-directory-name> $longname = 'a' * 250
PS C:\Temp\longish-directory-name> New-Item -ItemType Directory $longname


    Directory: C:\temp\longish-directory-name


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        5/30/2017   8:59 PM                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                                 aaaaaaaaaa

PS C:\Temp\longish-directory-name> Test-Path $longname
False
PS C:\Temp\longish-directory-name> Set-Location aa<TAB>
PS C:\Temp\longish-directory-name> Set-Location $longname
Set-Location : Cannot find path 'C:\temp\longish-directory-name\aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
because it does not exist.
At line:1 char:1
+ Set-Location $longname
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\temp\longish...aaaaaaaaaaaaa
   aa:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLo
   cationCommand

PS C:\Temp\longish-directory-name> Remove-Item $longname
Remove-Item : Cannot find path 'C:\temp\longish-directory-name\aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
because it does not exist.
At line:1 char:1
+ Remove-Item $longname
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\temp\longish...aaaaaaaaaaaaa
   aa:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Remov
   eItemCommand

Expected behavior

The long-named sub-directory was successfully created, so

  • Test-Path $longname should return True
  • Set-Location aa<TAB> should expand to the long directory name
  • Set-Location $longname should change to the long-named sub-directory
  • After returning to the parent directory, Remove-Item $longname should delete the directory

All of these work correctly on Unix environments.

Actual behavior

  • Test-Path $longname returns False
  • Set-Location aa<TAB> does nothing
  • Set-Location $longname fails with cannot-find-path error
  • Remove-Item $longname fails with cannot-find-path error

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
BuildVersion                   3.0.0.0
CLRVersion
GitCommitId                    v6.0.0-beta.1-32-g5cc46d9bcd9627f4a62b3c4825d...
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productOS-WindowsResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions