Skip to content

Conversation

@pougetat
Copy link

PR Summary

This PR "fixes" the current behavior for get-module with -FullyQualifiedName specified and containing a path. Unfortunately this does mean that this PR is a breaking change.

To illustrate the current behavior and the new behavior we can look at the following example :
/Foo/1.0/Foo.psd1
/Foo/2.0/Foo.psd1
Get-module -ListAvailable -FullyQualifiedName @{ModuleName = "/Foo"; ModuleVersion = "2.0"}

This will return both modules since "/Foo" is not correctly matched to either .psd1 file and the current behavior is to skip the version checks and simply return the modules.
With this PR the names are correctly matched and the version checks can take place thus resulting in only one module being returned.

PR Context

This PR is related to the following issues :
#8936 (meta-issue tracking refactoring work on module commandlets in general)
#8262

PR Checklist

@pougetat
Copy link
Author

CodeFactor is raising one issue (private static methods must come before non static private methods) which is not respected in other parts of the file that I have not modified. :)

@rjmholt rjmholt requested review from SteveL-MSFT and rjmholt and removed request for BrucePay March 26, 2019 17:02
@rjmholt rjmholt added Review - Committee The PR/Issue needs a review from the PowerShell Committee Breaking-Change breaking change that may affect users labels Mar 26, 2019
Copy link
Collaborator

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

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

@pougetat would you be able to give a concrete example of the change this makes in a comment in this PR along with an explanation of why it's a breaking change and tag the @PowerShell/powershell-committee? That way they can discuss and review it.

// FullyQualifiedName.Name could be a path, in which case it will not match module.Name.
// This is potentially a bug (since version checks are ignored).
// We should normalize FullyQualifiedName.Name here with ModuleIntrinsics.NormalizeModuleName().
FullyQualifiedName = FullyQualifiedName.Select(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we already have some LINQ usage here, but if we can avoid it I'd like to. As nice as it is, the GC pressure it creates is a performance drain.

@pougetat
Copy link
Author

pougetat commented Mar 26, 2019

@PowerShell/powershell-committee
Also tagging @SteveL-MSFT and @daxian-dbw since @PowerShell/powershell-committee not hoverable.

Here is an example that illustrates the behavior differences introduced with this PR.

Consider the following environment :

/foo/1.0/foo.pds1 => version 1.0 specified in the manifest
/foo/2.0/foo.psd1 => version 2.0 specified in the manifest

When executing the following command :

Get-module -ListAvailable -FullyQualifiedName @{ModuleName = "./foo"; ModuleVersion = "2.0"}

the old behavior yields :

ModuleType        Version       Name
-----------     -----------   --------
Manifest            2.0          foo
Manifest            1.0          foo

the new behavior yields :

ModuleType        Version       Name
-----------     -----------   --------
Manifest            2.0          foo

This is a breaking change for anyone counting on the fact that both modules would be returned even though this behavior seems counter-intuitive.

@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee reviewed this and agree with the change in behavior as it's unlikely someone has been dependent on this existing behavior

@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 Mar 27, 2019
@pougetat
Copy link
Author

@rjmholt
Thanks for the approval and the review. I am still going to remove the extra linq expressions to not create too much garbage as you requested so this isn't quite ready to merge.

@pougetat
Copy link
Author

@adityapatwardhan @rjmholt Hey,
I have updated the PR to remove the Linq expression 😄

@adityapatwardhan adityapatwardhan merged commit 0ee5278 into PowerShell:master Mar 29, 2019
@adityapatwardhan
Copy link
Member

@pougetat Thank you for your contribution!

@TravisEz13 TravisEz13 added this to the 6.3.0-preview.1 milestone Mar 29, 2019
@adityapatwardhan adityapatwardhan added CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log labels Mar 29, 2019
@LaurentDardenne
Copy link

As a result of this change, as I understand it, should not the ModuleSpecification class help specify that its Name property can also contain a path and not just a module name?

@rjmholt
Copy link
Collaborator

rjmholt commented May 31, 2019

As a result of this change, as I understand it, should not the ModuleSpecification class help specify that its Name property can also contain a path and not just a module name?

Yes it should. I believe that was always intended to work, since ModuleSpecifications are how RequiredModules in PSD1s are loaded.

@rjmholt
Copy link
Collaborator

rjmholt commented May 31, 2019

@LaurentDardenne which help are you talking about?

@LaurentDardenne
Copy link

@LaurentDardenne which help are you talking about?

This one

@rjmholt
Copy link
Collaborator

rjmholt commented May 31, 2019

Oh -- that comes from comment help! (In the XML comments)

{
foreach (ModuleSpecification moduleSpec in moduleSpecTable.Values)
{
if (moduleSpec.Name == module.Name || moduleSpec.Name == module.Path || module.Path.Contains(moduleSpec.Name))
Copy link
Member

Choose a reason for hiding this comment

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

FYI, this make existing cases of getting a module by name, using FullyQualifiedName case sensitive. I'll submit a PR to fix this.

TravisEz13 added a commit to TravisEz13/PowerShell that referenced this pull request Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log 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.

7 participants