Repository navigation
Closed
Labels
Area-FileSystem-Providerspecific to the FileSystem providerIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.Waiting - DotNetCorewaiting on a fix/change in .NET
Description
Note: The problem:
-
affects only files, not also directories
-
for file paths, affects all path components.
Simple demonstration (macOS and Windows):
PS> (Get-Item $PSHOME/POWERSHELL.config.json).Name
POWERSHELL.config.jsonNote how POWERSHELL.config.json was reported via .Name - exactly as specified - even though the actual casing of the filename is powershell.config.json
Steps to reproduce
Windows and macOS only (platforms with case-insensitive (but case-preserving) file-systems).
# Note: The problem occurs only with *files*, not directories.
# With files, the problem occurs in all path components.
Describe "Get-Item / Get-ChildItem: non-wildcard file-name case fidelity test" {
BeforeAll {
Push-Location (Get-Item testdrive:/).FullName
$nameActual = 'AB'
$nameCaseVariant = 'aB'
New-Item $nameActual # create as all-uppercase
$testCases =
@{ Cmdlet = 'Get-Item'; Parameter = 'Path'; Property = 'Name' },
@{ Cmdlet = 'Get-Item'; Parameter = 'Path'; Property = 'FullName' },
@{ Cmdlet = 'Get-Item'; Parameter = 'LiteralPath'; Property = 'Name' },
@{ Cmdlet = 'Get-Item'; Parameter = 'LiteralPath'; Property = 'FullName' },
@{ Cmdlet = 'Get-ChildItem'; Parameter = 'Path'; Property = 'Name' },
@{ Cmdlet = 'Get-ChildItem'; Parameter = 'Path'; Property = 'FullName' },
@{ Cmdlet = 'Get-ChildItem'; Parameter = 'LiteralPath'; Property = 'Name' },
@{ Cmdlet = 'Get-ChildItem'; Parameter = 'LiteralPath'; Property = 'FullName' }
}
It "<Cmdlet>: .<Property> should report '$nameActual' as the file name when literal case variant '$nameCaseVariant' is passed to <Parameter>" -Skip:$IsLinux -TestCase $testCases {
param($Cmdlet, $Parameter, $Property)
$htArgs = @{ $Parameter = $nameCaseVariant }
Split-Path -Leaf (& $Cmdlet @htArgs).$Property | Should -BeExactly $nameActual
}
AfterAll {
Pop-Location
}
}Expected behavior
The tests should succeed.
Actual behavior
All tests fail.
Environment data
PowerShell Core 7.1.0-preview.5
Metadata
Metadata
Assignees
Labels
Area-FileSystem-Providerspecific to the FileSystem providerIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.Waiting - DotNetCorewaiting on a fix/change in .NET
Activity
vexx32 commentedon Jul 16, 2020
Michael Klement (@mklement0) does directly calling a .NET API to retrieve the name report it with the correct casing?
mklement0 commentedon Jul 16, 2020
Good point, Rain Sallow (/u/ta11ow) (@vexx32) - indeed, the underlying .NET Core API - as well as .NET Framework - does the same:
However, it does so for directories too - whereas PowerShell (Core only!) exhibits the desired behavior:
So the question is:
Is reporting the true names for directories just a happy implementation accident, or is it by design?
If the latter, do we want to provide the same behavior for files too?
vexx32 commentedon Jul 16, 2020
I'd imagine since we're interested in supporting Unix that we'd want casing to be accurate, aye.
I'm surprised .NET Core hasn't got that ironed out yet, it'll make things very complicated for Unix developers wanting to use those APIs 😬
mklement0 commentedon Jul 16, 2020
Well, it's not strictly a functional problem, because it only applies to platforms with case-insensitive file systems, notably macOS and Windows - on Linux, with its case-sensitive file system you have to supply the case-accurate representation to begin with, otherwise you won't find the file / directory.
Still, I imagine that users consistently expect to get the true casing of file-system items when they call
Get-ItemorGet-ChildItem- after all, they get objects back that describe the item's own properties, which should not depend on the particular path form you chose to locate that item.I'm surprised that no one (to my knowledge, based on searching through the issues) has complained in the .NET Core repo about this.
iSazonov commentedon Jul 20, 2020
I'd speculate that it is because performance reasons - re-combine all path is very expensive. See #9250 as sample.
mklement0 commentedon Jul 20, 2020
So there's no single system call on all platforms with case-insensitive file-systems that would give you the case-exact form of a path (e.g., returning
C:\Windows\System32\APHostRes.dllforc:\windows\system32\aphostres.dll)?Given that we currently do it - but for directories only - how do we do it?
iSazonov commentedon Jul 20, 2020
Yes, only way to get an original value is to read from system.
See #9250. GetCorrectCasedPath() explicitly does this for directories.
mklement0 commentedon Jul 20, 2020
Thanks for the link, Ilya (@iSazonov).
I think it's more important for us to make
Get-ItemandGet-ChildItemexhibit consistent behavior in this respect than to worry about performance.Performance is more likely to be a concern when enumerating file-system items, but here we're talking about targeting a given file (pattern), and wanting to know its true name.
Note that there are more inconsistencies:
Again: If I use
Get-ItemandGet-ChildItem, I expect to get information objects that reflect the item's true name and path, not whatever case variation I happen to have used to identify the item.iSazonov commentedon Jul 20, 2020
Personally I do not like strongly #9250 and GetCorrectCasedPath(). I think if a system is case-insensitive we should follow this - accept a path as user typed and expose an enumerated path in case as it saved in the system. It is less expensive and more predictable. cmd.exe does so:
but PowerShell does extra work:
dir c:\windows Directory: C:\Windowsmklement0 commentedon Jul 20, 2020
We already do honor this for referring to paths and would continue to do so, but since these file systems are also case-preserving, we should honor that too, by reporting the actual name/path when explicitly requesting information about an item.
Yes,
cmd.exeand .NET act differently - but we can do better:The extra work that PowerShell already does for directories is helpful - let's do the work for files too.
Again: The incidental form of a path I use to refer to an item of interest (case variations, relative vs. absolute path) should not change how its innate properties are being reported.
iSazonov commentedon Jul 20, 2020
Helpful?
If I type "c:\WinDowS" it is my strong intention to work exactly with "c:\WinDowS". And it works! Why should the system change this to "C:\Windows" for me?
It seems we even have a case(-s) about this. Like why expanded:
mklement0 commentedon Jul 20, 2020
26 remaining items
iSazonov commentedon Aug 19, 2020
Proposed API in .Net Runtime dotnet/runtime#14321
For Windows we could use more fast a workaround
See https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
/cc Steve Lee (@SteveL-MSFT) for tracking .Net issue
mklement0 commentedon Aug 19, 2020
Ilya (@iSazonov), thanks for the link.
As for the workaround:
GetFinalPathNameByHandle()resolves symlinks to their ultimate targets, which we don't want to do by default; asking for the properties of a symlink withGet-Itemshould return the symlink's name in.Name; ditto with parent paths that have symlink components (even if the target item itself is not a reparse point).microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.