8000 Fixing Import-Module on Linux for special cases of NestedModules/RootModule path format by anmenaga · Pull Request #4010 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fixing Import-Module on Linux for special cases of NestedModules/RootModule path format #4010

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

Merged
merged 3 commits into from
Jun 28, 2017

Conversation

anmenaga
Copy link

NestedModules/RootModule are fields in a module manifest (.psd1) that reference other modules using string paths. Assuming that a module is written to be cross-platform, the same psd1 module manifest should be successfully imported on both Windows and Linux platforms.
The bug is that in some cases Import-Module on Linux fails for a totally valid module. It depends on format of NestedModules/RootModule paths.

The root of the problem is using simple Path.Combine for constructing a path to the submodule, that is then tested using NativeItemExists methods, resulting in calls like
Unix.NativeMethods.IsFile("/home/testuser/TestRootModule/.\SubModule\SubModule.psm1")
which fails and Import-Module returns an error.

The fix is to resolve submodule paths using existing FileSystem provider utilities.

Test results on Ubuntu 14 after the fix:
afterfix

Test results on Ubuntu 14 before the fix:
beforefix

Fix #3693

Import-Module $moduleFilePath
(Get-Module $moduleName).ExportedCommands.Keys.Contains('TestModuleFunction') | Should Be $true
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The little red icon means you should have a trailing linefeed at the end of the file

Copy link
Author

Choose a reason for hiding this comment

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

I always forget about that newline... Updated.

Copy link
Member
@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@mirichmo mirichmo self-assigned this Jun 22, 2017
@mirichmo mirichmo merged commit ecefb50 into PowerShell:master Jun 28, 2017
@anmenaga anmenaga deleted the ImportingModulePathFix branch October 31, 2018 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NestedModules does not work on Linux if the path starts with '.' e.g. '.\folder\library.dll'
4 participants
0