Skip to content

Conversation

@renehernandez
Copy link
Contributor

@renehernandez renehernandez commented Jan 3, 2019

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
Copy link

msftclas commented Jan 3, 2019

CLA assistant check
All CLA requirements met.

@iSazonov iSazonov added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Jan 3, 2019
@iSazonov
Copy link
Collaborator

iSazonov commented Jan 3, 2019

@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
Member

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

@SteveL-MSFT 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 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
Copy link

stale bot commented Mar 3, 2019

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
Contributor Author

@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
Member

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

Copy link
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
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
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
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
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
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
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
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
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.
@SteveL-MSFT @joeyaiello what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@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
Member

@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.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

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

@renehernandez renehernandez force-pushed the provider-info-path-separator branch from 668381c to 8f44042 Compare March 9, 2019 20:26
@daxian-dbw
Copy link
Member

@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
Contributor Author

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

@daxian-dbw
Copy link
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;}

@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 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
Copy link
Member

daxian-dbw commented Mar 11, 2019

@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
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.

@mklement0
Copy link
Contributor

@SteveL-MSFT: Please see #9244

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
@renehernandez renehernandez force-pushed the provider-info-path-separator branch from 50c7127 to a905ca0 Compare March 29, 2019 23:43
Copy link
Member

@daxian-dbw daxian-dbw left a comment

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 @renehernandez!

@iSazonov
Copy link
Collaborator

iSazonov commented Apr 2, 2019

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
Member

The issue tracking registry provider is #5536

@daxian-dbw daxian-dbw merged commit 75da390 into PowerShell:master Apr 2, 2019
@daxian-dbw
Copy link
Member

@renehernandez Thank you again for your contribution and patience!

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