-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix Get-Module -FullyQualifiedName option to work with paths #9101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Get-Module -FullyQualifiedName option to work with paths #9101
Conversation
|
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
left a comment
There was a problem hiding this 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( |
There was a problem hiding this comment.
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.
|
@PowerShell/powershell-committee 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 When executing the following command : Get-module -ListAvailable -FullyQualifiedName @{ModuleName = "./foo"; ModuleVersion = "2.0"}the old behavior yields : the new behavior yields : This is a breaking change for anyone counting on the fact that both modules would be returned even though this behavior seems counter-intuitive. |
|
@PowerShell/powershell-committee reviewed this and agree with the change in behavior as it's unlikely someone has been dependent on this existing behavior |
|
@rjmholt |
|
@adityapatwardhan @rjmholt Hey, |
|
@pougetat Thank you for your contribution! |
|
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. |
|
@LaurentDardenne which help are you talking about? |
|
|
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)) |
There was a problem hiding this comment.
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.
fix regression caused in PowerShell#9101
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
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.[feature]to your commit messages if the change is significant or affects feature tests