-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Change Get-ChildItem to treat trailing slash in path as indicating a directory when used with -Recurse
#17704
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
Change Get-ChildItem to treat trailing slash in path as indicating a directory when used with -Recurse
#17704
Conversation
…a directory when used with `-Recurse`
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
src/System.Management.Automation/engine/SessionStateContainer.cs
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1
Show resolved
Hide resolved
|
@SteveL-MSFT Please update the PR summary - the description confuses rather than adds to the understanding. |
Co-authored-by: Paul Higinbotham <paulhi@microsoft.com>
|
@iSazonov just to be clear, is the first part which is more about the issue than the fix the confusing part? I can just remove that. Or is it the second part trying to explain the root cause and the change? |
As for my second comment, I did not investigate why my example doesn't work but before we merge the PR I'd want to understand whether it is that issue or another issue. Could you please confirm the PR fix it too? |
|
@iSazonov ok, now I understand what you are saying. I'll remove those two lines as they aren't correct. I'll investigate your use case to understand what is happening. |
|
🎉 Handy links: |
PR Summary
If you run this command:
and the subfolder
bardoes not exist and a subfolder calledbdoesn't exist, you get an incorrect error message:The problem is that the code is trying to find the parent of bar, which should be
C:\foo\but because of the trailing slash, it has an off-by-one error resulting inc:\foo\b. It then tries to find this folder which results in the error message. If by chance a folderbexists, thenGet-ChildItemwould traverse into that folder and return incorrect results.The fix here is if the path ends in a trailing slash, then we treat the last part as indicating a directory and never a folder. So we add checks for that and if "c:\foo\bar" where a folder "bar" doesn't exist, you'll get the right error message with the path.
However, part of the fix works around an issue with .NET FileInfo::new() which happily accepts a path to a file with a trailing slash and returns an incomplete object. Since this repros with .NET Framework, it seems unlikely to be changed (
Get-Itemdemonstrates the behavior and is not changed in this PR) so I added code to fail if such an object is returned.PR Context
This issue was brought up in this thread: https://twitter.com/SBarizien/status/1549000209610510336
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).