Skip to content

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

Merged
mirichmo merged 3 commits intoPowerShell:masterfrom
anmenaga:ImportingModulePathFix
Jun 28, 2017
Merged

Fixing Import-Module on Linux for special cases of NestedModules/RootModule path format#4010
mirichmo merged 3 commits intoPowerShell:masterfrom
anmenaga:ImportingModulePathFix

Conversation

@anmenaga
Copy link
Copy Markdown

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
}
} No newline at end of file
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.

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

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