Repository navigation
Description
Follow-up from #13640.
PR #12386 introduced experimental feature PSNativePSPathResolution, which as of (at least) PowerShell Core 7.1.0-preview.7 has become a default feature.
Its purpose is to translate PowerShell-drive-based paths to native filesystem paths, because external executables only understand the latter.
While this is likely helpful in most cases, there are two problems, both stemming from the fact that PowerShell cannot know whether a given argument passed to an external program indeed represents a file path:
-
There must be a way to bypass this translation, in case an argument that happens to look like a PSDrive-based path should be passed as-is.
- Currently, the only way to bypass the translation is to use single-quoting (e.g,
'temp:foo'rather than unquotedtemp:fooor double-quoted"temp:foo", but this is problematic for two reasons:- This distinction is obscure, because the user is likely to conceive of both
'temp:foo'and"temp:foo"as literals, which in any other context they are. - More importantly: it only works for literal arguments, and not for variables and expressions.
- This distinction is obscure, because the user is likely to conceive of both
- Currently, the only way to bypass the translation is to use single-quoting (e.g,
-
Even with such a mechanism, however, the problem is that bypassing may only be situationally necessary, depending on what custom PS drives happen to be defined at the time of the external-program call, so you cannot really anticipate when bypassing is necessary.
I see two possible solutions:
-
(a) Roll back the feature, recognizing that it is ultimately too fraught (it hasn't been in any official release yet).
-
(b) Minimize the risk of false positives as follows, but note that their complete elimination isn't possible:
-
Currently, the translation is triggered by any argument with a prefix that looks like a drive specification of a custom PS drive (e.g.,
temp:) irrespective of what follows: that is, it doesn't matter whether the path refers to an existing item or even if the path is syntactically correct. -
There will be far fewer false positives if the translation is only performed if the argument refers to an existing file-system path; e.g.,
temp:fooshould only be translated if a file or directory attemp:/fooactually exists. -
However, this implies:
- Users may be confused when a non-existing path they expected to exist goes untranslated.
- Arguments may by design represent not-yet-extant paths, such as when passing an output file path.
- A bypass mechanism is still needed, one that also supports passing arguments via variables and expressions; though perhaps the need for it will be so rare that the limited
--%will do.
-
Steps to reproduce
The following is predicated on suggestion (b) above, i.e., only performing translation for existing PSDrive-based paths, and assumes that no file/dir. exists at temp:/foo
On Unix (use cmd /c echo on Windows):
$arg = 'temp:foo'; /bin/echo $arg | Should -be $argExpected behavior
The test should pass, because since temp:foo doesn't refer to an existing file-system path, it should be passed as-is.
Actual behavior
The test fails, because the temp:foo is translated to (Get-PSDrive temp).Root + ':/foo', even though temp:/foo doesn't exist; e.g., on macOS:
Expected: 'temp:foo' But was: '/var/folde...'
Environment data
PowerShell Core 7.1.0-preview.7
Activity
iSazonov commentedon Sep 17, 2020
Michael Klement (@mklement0) Since you define the PSNativePSPathResolution feature as " the current feature is guesswork", and we see some side effects and haven't a bypass mechanism I think it is better to exclude the feature from 7.1 version.
/cc Joey Aiello (@joeyaiello) Steve Lee (@SteveL-MSFT)
SteveL-MSFT commentedon Oct 2, 2020
For 7.1, I think it's best to put it back as an experimental feature, so I'll prep a PR for that
SteveL-MSFT commentedon Jul 12, 2022
I had looked into this and the problem is by the time the NativeCommandProcessor gets the arg, there is no way to differentiate single vs double quotes. At this point, it's not worth the effort to fix this so I'm removing this feature altogether as other than the default temp drive, I don't think many people are using custom filesystem psdrives where this feature is useful.
KyleKolander commentedon Sep 12, 2022
Dang Steve Lee (@SteveL-MSFT), I recently added several
PSDrives to my profile - what a cool and really useful feature! Then I discovered that they don't work for other command line tools likegit. I can usegit log (Convert-Path MyDrive:\src\Test.csproj), but who wants to always remember to wrap parens around the path and pass it toConvert-Path? I was about to throw in the towel and then I saw your PR to add this experimental feature, turned it on and voila - it works as one would expect it to (within the confines of a PowerShell session). Then I saw it had been removed for 7.3. So disappointing. I get it that you can only support so many different features and have to prioritize based on usage. Is there is any way you could justify keeping it around as an experimental feature (and document the edge cases to mitigate confusion)?SteveL-MSFT commentedon Sep 12, 2022
Kyle Kolander (@KyleKolander) maybe someone can take my PR and address the edge cases in the future
KyleKolander commentedon Sep 12, 2022
Fair enough. I had to at least ask. 😄 I'll use Directory Junctions instead. Lacks the syntactic sugar of the PSDrive, but it also works across all of Windows (not just within PowerShell).