Skip to content

Add support for PathSeparator property in Providers - #8587

Merged
Dongbo Wang (daxian-dbw) merged 18 commits into
PowerShell:masterfrom
renehernandez:provider-info-path-separator
Apr 2, 2019
Merged

Dongbo Wang (daxian-dbw) merged 18 commits into
PowerShell:masterfrom
renehernandez:provider-info-path-separator

Conversation

@renehernandez

@renehernandez Rene Hernandez (renehernandez) commented Jan 3, 2019 •

Copy link
Copy Markdown
Contributor

PR Summary

Fix #5544.

Add two properties in ProviderInfo class: ItemSeparator and AltItemSeparator.
On windows, the default values for those two properties are ItemSeparator = '\' and AltItemSeparator = '/'.
On unix, the default values for those two properties are ItemSeparator = '/' and AltItemSeparator = '\'.

Registry provider is the only exception, both properties for it have the value \.

PR Checklist

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Jan 3, 2019 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@iSazonov Ilya (iSazonov) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Jan 3, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator

Rene Hernandez (@renehernandez) Thanks for your contribution!

I added 'Fix #5544' to link the issue and auto close it after we merge.

The public API should be approved by PowerShell Committee.

@SteveL-MSFT

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee reviewed this and is ok with adding PathSeparator

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jan 9, 2019
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 10, 2019
@stale

stale Bot commented Mar 3, 2019

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale Bot added the Stale label Mar 3, 2019
@renehernandez

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw) Is this going to be merged at all? The changes are pretty small and they shouldn't be to hard to review.

Or is there anything left that should be addressed??

@stale stale Bot removed the Stale label Mar 4, 2019
@daxian-dbw

Copy link
Copy Markdown
Member

Rene Hernandez (@renehernandez) Sorry for having this PR slip off my radar. I will do the review later today.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar method should be added for Environment, Alias, Certificate and WSMan providers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have yet to add it for the WSMan provider. The reason is that WSMan provider is in a different namespace, thus would require to change classes in the Utils file to have public scope

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you should be the outcome here? Should I change the relevant classes' scope?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think we can use a new instance of ReadOnlyCollection<string> for WSMan.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, should we allow string that is more than 1 chars to be used as the path separator? Maybe ReadOnlyCollection<char>?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as for the default value of this property, maybe it should be null by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to apply these changes?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be discreet here as it's a public API.
Steve Lee (@SteveL-MSFT) Joey Aiello (@joeyaiello) what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dongbo Wang (@daxian-dbw)'s feedback makes sense to me. I'm not aware of any situation where the separator is more than a single character.

@daxian-dbw

Copy link
Copy Markdown
Member

Rene Hernandez (@renehernandez) When you are addressing my comments, can you please add the [Feature] tag to the last commit's message? I would like the CI to run all feature tests for this PR.

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me. Thanks! Let's wait for Steve and Joe's feedback on string vs. char.
Can you please rebase when push your next commit?

can you please add the [Feature] tag to the last commit's message? I would like the CI to run all feature tests for this PR.

And please, add the [Feature] tag to the last commits's message. Thanks

@daxian-dbw

Copy link
Copy Markdown
Member

Rene Hernandez (@renehernandez) I think we need to implement the PathSeparator property in a different way.
Here is my suggestion:
Add a public virtual get-only property PathSeparators in CmdletProvider. The default implementation can be this:

public virtual ReadOnlyCollection<string> PathSeparators => Utils.EmptyReadOnlyCollection<string>();

Then, add a public-getter-private-setter property PathSeparators in ProviderInfo. The default implementation can be this:

public ReadOnlyCollection<string> PathSeparators { get; private set; }

Then, in the ProviderInfo.CreateInstance, after casting providerInstance to CmdletProvider, we set the PathSeparators property in the Provider instance:

Provider.CmdletProvider result = providerInstance as Provider.CmdletProvider;
PathSeparators = result.PathSeparators;

Then, in each provider implementation, override that property to provide the supported separators.

@renehernandez

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw) Are you suggesting a rename as part of the change? Should the property be plural, i.e. PathSeparators?

@daxian-dbw

Copy link
Copy Markdown
Member
PS:28> [System.IO.Path] | gm -Static
...
AltDirectorySeparatorChar   Property   static char AltDirectorySeparatorChar {get;}
DirectorySeparatorChar      Property   static char DirectorySeparatorChar {get;}
InvalidPathChars            Property   static char[] InvalidPathChars {get;}
PathSeparator               Property   static char PathSeparator {get;}
VolumeSeparatorChar         Property   static char VolumeSeparatorChar {get;}

Rene Hernandez (@renehernandez) If we look at how System.IO.Path name those properties, I think plural would be better as we return a collection. But let me check with the committee before we move forward.

@daxian-dbw Dongbo Wang (daxian-dbw) added Review - Committee The PR/Issue needs a review from the PowerShell Committee and removed Committee-Reviewed PS-Committee has reviewed this and made a decision labels Mar 11, 2019
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Mar 11, 2019 •

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee Need your another review on three items:

  1. Since the new property PathSeparator returns a collection (ReadOnlyCollection), shall we rename it to PathSeparators (plural)?
  2. Do we allow a string of more than 2 characters used as a path separator in PowerShell providers? If not, maybe make the property return ReadOnlyCollection<char>?
  3. Is it OK to add a public virtual get-only property PathSeparators in the public abstract class CmdletProvider? Implementation looks like this:
public virtual ReadOnlyCollection<string> PathSeparators => Utils.EmptyReadOnlyCollection<string>();

@mklement0

Copy link
Copy Markdown
Contributor

Here's my 2¢:

  • Re 1: I know it's late in the game, but, seeing the CoreFx approach of providing DirectorySeparatorChar and AltDirectorySeparatorChar separately, I wonder if we should similarly provide two scalar properties, PathSeparator and AltPathSeparator - given that my guess is that users will typically want the official separator, even though there may be an alternative (which, as far as native data stores go, really only applies to the filesystem on Windows).

  • Re 2: My vote is for string rather than char, for the following reasons:

    • Given that the property will (also) be consumed from PowerShell code, there is no advantage to using char over string, given that char is not a first-class type in PowerShell code, where even single characters are by default represented as strings.
    • It leaves the door open for providers with multi-character separators - though that is admittedly not very likely to happen.

Rene Hernandez Remedios and others added 18 commits March 29, 2019 19:37
Add PathSeparator values for FileSystem, Function, Variable and Registry
providers
Add corresponding tests
Fix that changes in a copy of the separator array could affect
subsequent calls of the PathSeparator property

Add test
Use test data accordingly to OS, ie. windows vs Unix-like
Fix expected values for providers for unix-like system
Add PathSeparator property to Env, Cert and Alias provider
Add test for property being read-only
Consolidate separator list in Separators class
Remove invalid test cases for nonwindows os
Remove unused overrides for Start method
Add tests for WSMan in ConfigProvider tests
Remove unused properties added to internal Separator class
Fix xml documentation
Remove unused namespace
Fix xml documentation tag
Remove base prefix from expression body

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized new commits were pushed. This looks good to me. Thank you Rene Hernandez (@renehernandez)!

@iSazonov

Copy link
Copy Markdown
Collaborator

today the registry provider also accepts and normalizes / and . But we agreed that's not right and should be corrected in future.

Have we a tracking issue?

@daxian-dbw

Copy link
Copy Markdown
Member

The issue tracking registry provider is #5536

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 75da390 into PowerShell:master Apr 2, 2019
@daxian-dbw

Copy link
Copy Markdown
Member

Rene Hernandez (@renehernandez) Thank you again for your contribution and patience!

@iSazonov Ilya (iSazonov) added this to the 6.3.0-preview.1 milestone Apr 2, 2019
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…o` (PowerShell#8587)

Add two properties in `ProviderInfo` class: `ItemSeparator` and `AltItemSeparator`.
On windows, the default values for those two properties are `ItemSeparator = '\'` and `AltItemSeparator = '/'`.
On unix, the default values for those two properties are `ItemSeparator = '/'` and `AltItemSeparator = '\'`.

Registry provider is the only exception, both properties for it have the value `\`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants