Skip to content

[System.Management.Automation.ProviderInfo] (returned by Get-PSProvider) should contain path-separator information #5544

Closed
softagram/PowerShell
#1

Description

Currently, there is no way to learn of the path-separator character(s) that must be used to separate the components of a path for a given provider, because [System.Management.Automation.ProviderInfo], as returned by Get-PSProvider, has no such property.

In the absence of such information, users may be tempted to assume that \ and / can be universally - and interchangeably - used, which is not necessarily true; for instance, the registry provider only properly supports \, given that / is a valid char. in registry key names - see #5536

Future providers - or even existing third-party providers - could conceivably use completely different characters (of necessity).

Adding a [string[]]-typed .PathSeparator property to [System.Management.Automation.ProviderInfo] would help.

Additional considerations:

  • Non-hierarchical providers such as the Variable and Function providers have no real need for a path separator: e.g., Get-Item variable:PSHome works just fine. In practice, these providers follow the FileSystem provider's example and allow interchangeable use of / and \, and tab completion even explicitly inserts these optional chars.: / on Unix, and \ on Windows.

  • Third-party implementers of providers will need to provide appropriate values for .PathSeparator too.

  • The name to give this new property is debatable, given that the .NET framework has already sown confusion around [System.IO.Path]::DirectorySeparator (the path-component separator) vs. [System.IO.Path]::PathSeparator (the path-environment-variable-entry separator). However, given that the term directory is filesystem-specific and we're talking about abstractions here, my vote is still for .PathSeparator.

Desired behavior

> Get-PSProvider FileSystem | % PathSeparator
\
/

> Get-PSProvider Registry | % PathSeparator
\

Environment data

PowerShell Core v6.0.0-rc

Activity

  1. added
    WG-Engine-Providers
    Issue-Enhancement
    on Nov 25, 2017
  2. added
    Up-for-Grabs
    on Mar 2, 2018
  3. renehernandez commented on Jan 2, 2019

    @renehernandez
    Contributor

    Michael Klement (@mklement0) I am working on this issue,

    So far, I have already added a PathSeparator property on the ProviderInfo class.

    Now I am going through the code to figure out where do I have to set the values for PathSeparator in each of the Provider. For what I have read in the code the best location to update the property would be in the Start method of each the provider.

    Any suggestions?

  4. vexx32 commented on Jan 3, 2019

    @vexx32
    Collaborator

    That seems like a good start to me Rene Hernandez (@renehernandez). 😄

    I would recommend doing what you can to get it to a point where it works, add some tests in, and then open a PR. If the PS Team want to direct you to better or more apropos places to put specific details in, they'll be happy to do it there, where they can see the changes you've made. 🙂

  5. iSazonov commented on Jan 6, 2019

    @iSazonov
    Collaborator

    given that the term directory is filesystem-specific and we're talking about abstractions here, my vote is still for .PathSeparator.

    My first look was on FileSystem provider and the name confused me. It will always confuse users in the context. So I think we need another abstraction name.
    We use New-Item for all providers and Item corresponds "item of path" in FileSystem provider. I'd expect that .Net Core [System.IO.Path]::PathSeparator transforms to ItemSeparator.
    On the other hand, we have Join-Path. If we had a PathSeparator parameter there, what would it mean? Again confuse.

  6. mklement0 commented on Jan 7, 2019

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): I'm not sure I understand all your points, but let me try to respond:

    It will always confuse users in the context. So I think we need another abstraction name.

    Why? To me, the confusion stems only from [System.IO.Path]::PathSeparator, but I don't think we should worry about that - it's .NET's confusion, not PowerShell's.

    Strictly speaking, we're looking for the character that is used to separate item names that are sequenced to form a path - PathSeparator seems like the most intuitive choice to me.

    I guess ItemSeparator would work too, but to me it's preferable to mention the relevant concept in the name: a path [of item names].

    I'd expect that .Net Core [System.IO.Path]::PathSeparator transforms to ItemSeparator.

    [System.IO.Path]::PathSeparator has no relationship to providers per se, and shouldn't be reflected there - it's a character used by convention to separate paths as a whole in a reserved environment variable (and, as an aside, is itself a legal filename character on its respective platforms). Whether and where to represent this other separator in PowerShell too is a separate question; my name suggestion would be PathVariableSeparator.

    On the other hand, we have Join-Path. If we had a PathSeparator parameter there, what would it mean? Again confuse.

    In line with the new property, it would refer to the separator used to separate item names in a path - where is the confusion?

  7. vexx32 commented on Jan 7, 2019

    @vexx32
    Collaborator

    Agreed with using PathVariableSeparator or even something a degree more removed perhaps, like PathVariableDelimiter because its function is so completely different to PathSeparator; it's not separating portions of a path, it's usually a character that can't be used in a path at all, so it serves to clearly delimit individual values in the environment variable.

  8. mklement0 commented on Jan 7, 2019

    @mklement0
    ContributorAuthor

    Thanks, Rain Sallow (/u/ta11ow) (@vexx32), but I suggest sticking with "separator" as the most familiar term (for which "delimiter" is a near-synonym with no clear distinction), because in the abstract the functionality is the same:

    A list or sequence (path) is formed from entries, and a character is placed between those entries to mark their boundaries.

    The entries just happen to be different entities:

    • In the case of $env:PATH, the entities happen to be filesystem paths themselves (and, as stated, strictly speaking you can use : in filesystem paths on Unix, and ; on Windows, but it's probably a bad idea).
    • In the case of a provider path, the entities happen to be item names (file/directory names, in the case of the filesystem provider)
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-EnhancementResolution-FixedUp-for-GrabsWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions