-
-
Notifications
You must be signed in to change notification settings - Fork 3
fix: relative path handling in Find-Item #18
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
Conversation
By default if you pass a relative path to the .NET APIs, it will use [Environment]::CurrentDirectory as its base, not your actual PowerShell working directory. The problem is that the two are almost never the same. This changes it so that the entry path is resolved by PowerShell, not .NET.
|
Definitely not finished yet, found a fun bug wherein if the path doesn't resolve, the Path variable is never updated, and so a failed path ends up looking in I'll fix it and will ensure there are tests before going live with this. |
PowerShell expects things to be written to Write-Error so they can be handled in a standard fashion based on the ErrorActionPreference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes relative path handling in the Find-Item function to use PowerShell's working directory instead of .NET's Environment.CurrentDirectory, which are typically different. This allows users to pass relative paths that resolve correctly from their current PowerShell location.
- Uses PSCmdlet.GetResolvedProviderPathFromPSPath to resolve paths in PowerShell context
- Updates error handling to use Write-Error instead of throwing exceptions
- Improves parameter documentation clarity
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@cdonnellytx sorry, i completely missed your issue and pull request. also i didn't looked into this repository for a long time. |
…anged in newer versions) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
When using the provider, since |
By default if you pass a relative path to the .NET APIs, it will use [Environment]::CurrentDirectory as its base, not your actual PowerShell working directory.
The problem is that the two are almost never the same.
This changes it so that the entry path is resolved by PowerShell, not .NET.
Description
This resolves relative paths to absolute in PowerShell's working directory context instead of .NET's.
By default if you pass a relative path to the .NET APIs, it will use [Environment]::CurrentDirectory as its base, not your actual PowerShell working directory.
The problem is that the two are almost never the same.
This changes it so that the entry path is resolved by PowerShell, not .NET, by using PSCmdlet.GetResolvedProviderPathFromPSPath to resolve the path.
Related Issue
#19
Motivation and Context
It lets me specify relative paths to Find-Item.
How Has This Been Tested?
Ran
Find-Itemmanually:Find-ItemFind-Item foo$PWD\fooinstead of$HOME\fooFind-Item D:\github\cdonnellytx\fooFind-Item 'Microsoft.PowerShell.Core\FileSystem::D:\github\cdonnellytx\foo'D:\github\cdonnellytx\fooScreenshots (if appropriate):
Types of changes
Checklist: