-
Notifications
You must be signed in to change notification settings - Fork 107
Exclude dependency from RequiredModules when listed under ExternalModuleDependencies #1973
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
Open
anamnavi
wants to merge
4
commits into
master
Choose a base branch
from
bugfix-externalmoduledependecies
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−14
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5df1e3b
Ignore dependency listed in ExternalModuleDependencies from RequiredM…
anamnavi ec6480f
Clean up verbose message
anamnavi 0424405
Add tests for Save-PSResource and Install-PSResource
anamnavi 54c0af8
Merge branch 'master' of https://github.com/PowerShell/PSResourceGet …
anamnavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -558,14 +558,15 @@ private List<PSResourceInfo> InstallPackages( | |
|
|
||
| Hashtable parentPkgInfo = packagesHash[parentPackage] as Hashtable; | ||
| PSResourceInfo parentPkgObj = parentPkgInfo["psResourceInfoPkg"] as PSResourceInfo; | ||
| string[] externalModuleDependencies = parentPkgInfo["externalModuleDependencies"] as string[]; | ||
|
|
||
| if (!skipDependencyCheck) | ||
| { | ||
| // Get the dependencies from the installed package. | ||
| if (parentPkgObj.Dependencies.Length > 0) | ||
| { | ||
| bool depFindFailed = false; | ||
| foreach (PSResourceInfo depPkg in findHelper.FindDependencyPackages(currentServer, currentResponseUtil, parentPkgObj, repository)) | ||
| foreach (PSResourceInfo depPkg in findHelper.FindDependencyPackages(currentServer, currentResponseUtil, parentPkgObj, externalModuleDependencies, repository)) | ||
| { | ||
| if (depPkg == null) | ||
| { | ||
|
|
@@ -824,7 +825,8 @@ private Hashtable BeginPackageInstall( | |
| { "tempDirNameVersionPath", tempInstallPath }, | ||
| { "pkgVersion", "" }, | ||
| { "scriptPath", "" }, | ||
| { "installPath", "" } | ||
| { "installPath", "" }, | ||
| { "externalModuleDependencies", Utils.EmptyStrArray } | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -840,7 +842,8 @@ private Hashtable BeginPackageInstall( | |
| { "tempDirNameVersionPath", tempInstallPath }, | ||
| { "pkgVersion", "" }, | ||
| { "scriptPath", "" }, | ||
| { "installPath", "" } | ||
| { "installPath", "" }, | ||
| { "externalModuleDependencies", Utils.EmptyStrArray } | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -933,6 +936,7 @@ private bool TryInstallToTempPath( | |
| _cmdletPassedIn.WriteDebug("In InstallHelper::TryInstallToTempPath()"); | ||
| error = null; | ||
| updatedPackagesHash = packagesHash; | ||
| string[] externalModuleDependencies = Utils.EmptyStrArray; | ||
| try | ||
| { | ||
| var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip"); | ||
|
|
@@ -1004,6 +1008,11 @@ private bool TryInstallToTempPath( | |
| return false; | ||
| } | ||
|
|
||
| if (!RetrieveExternalModuleDependenciesForModule(pkgName, parsedMetadataHashtable, out externalModuleDependencies, out error)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Accept License verification | ||
| if (!CallAcceptLicense(pkgToInstall, moduleManifest, tempInstallPath, pkgVersion, out error)) | ||
| { | ||
|
|
@@ -1022,7 +1031,6 @@ private bool TryInstallToTempPath( | |
| { | ||
| installPath = _pathsToInstallPkg.Find(path => path.EndsWith("Scripts", StringComparison.InvariantCultureIgnoreCase)); | ||
|
|
||
| // is script | ||
| if (!PSScriptFileInfo.TryTestPSScriptFileInfo( | ||
| scriptFileInfoPath: scriptPath, | ||
| parsedScript: out PSScriptFileInfo scriptToInstall, | ||
|
|
@@ -1042,6 +1050,8 @@ private bool TryInstallToTempPath( | |
|
|
||
| return false; | ||
| } | ||
|
|
||
| externalModuleDependencies = scriptToInstall.ScriptMetadataComment.ExternalModuleDependencies; | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -1075,7 +1085,8 @@ private bool TryInstallToTempPath( | |
| { "tempDirNameVersionPath", tempDirNameVersion }, | ||
| { "pkgVersion", pkgVersion }, | ||
| { "scriptPath", scriptPath }, | ||
| { "installPath", installPath } | ||
| { "installPath", installPath }, | ||
| { "externalModuleDependencies", externalModuleDependencies } | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -1111,6 +1122,7 @@ private bool TrySaveNupkgToTempPath( | |
| _cmdletPassedIn.WriteDebug("In InstallHelper::TrySaveNupkgToTempPath()"); | ||
| error = null; | ||
| updatedPackagesHash = packagesHash; | ||
| string[] externalModuleDependencies = Utils.EmptyStrArray; | ||
|
|
||
| try | ||
| { | ||
|
|
@@ -1120,6 +1132,85 @@ private bool TrySaveNupkgToTempPath( | |
| responseStream.CopyTo(fs); | ||
| fs.Close(); | ||
|
|
||
| var pkgVersion = pkgToInstall.Version.ToString(); | ||
| var tempDirNameVersion = Path.Combine(tempInstallPath, pkgName, pkgVersion); | ||
| Directory.CreateDirectory(tempDirNameVersion); | ||
|
|
||
| if (!TryExtractToDirectory(pathToFile, tempDirNameVersion, out error)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var moduleManifest = Path.Combine(tempDirNameVersion, pkgName + PSDataFileExt); | ||
| var scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt); | ||
|
|
||
| bool isModule = File.Exists(moduleManifest); | ||
| bool isScript = File.Exists(scriptPath); | ||
|
|
||
| if (!isModule && !isScript) | ||
| { | ||
| scriptPath = ""; | ||
| } | ||
|
|
||
| if (isModule) | ||
| { | ||
| if (!File.Exists(moduleManifest)) | ||
| { | ||
| error = new ErrorRecord( | ||
| new ArgumentException("Package '{pkgName}' could not be installed: Module manifest file: {moduleManifest} does not exist. This is not a valid PowerShell module."), | ||
| "PSDataFileNotExistError", | ||
| ErrorCategory.ReadError, | ||
| _cmdletPassedIn); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| if (!Utils.TryReadManifestFile( | ||
| manifestFilePath: moduleManifest, | ||
| manifestInfo: out Hashtable parsedMetadataHashtable, | ||
| error: out Exception manifestReadError)) | ||
| { | ||
| error = new ErrorRecord( | ||
| manifestReadError, | ||
| "ManifestFileReadParseError", | ||
| ErrorCategory.ReadError, | ||
| _cmdletPassedIn); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| if (!RetrieveExternalModuleDependenciesForModule(pkgName, parsedMetadataHashtable, out externalModuleDependencies, out error)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| else if(isScript) | ||
| { | ||
| if (!PSScriptFileInfo.TryTestPSScriptFileInfo( | ||
| scriptFileInfoPath: scriptPath, | ||
| parsedScript: out PSScriptFileInfo scriptToInstall, | ||
| out ErrorRecord[] parseScriptFileErrors, | ||
| out string[] _)) | ||
| { | ||
| foreach (ErrorRecord parseError in parseScriptFileErrors) | ||
| { | ||
| _cmdletPassedIn.WriteError(parseError); | ||
| } | ||
|
|
||
| error = new ErrorRecord( | ||
| new InvalidOperationException($"PSScriptFile could not be parsed"), | ||
| "PSScriptParseError", | ||
| ErrorCategory.ReadError, | ||
| _cmdletPassedIn); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| externalModuleDependencies = scriptToInstall.ScriptMetadataComment.ExternalModuleDependencies; | ||
| } | ||
|
|
||
| DeleteExtraneousFiles(pkgName, tempDirNameVersion); | ||
|
|
||
| string installPath = _pathsToInstallPkg.First(); | ||
| if (_includeXml) | ||
| { | ||
|
|
@@ -1140,7 +1231,8 @@ private bool TrySaveNupkgToTempPath( | |
| { "tempDirNameVersionPath", tempInstallPath }, | ||
| { "pkgVersion", "" }, | ||
| { "scriptPath", "" }, | ||
| { "installPath", installPath } | ||
| { "installPath", installPath }, | ||
| { "externalModuleDependencies", externalModuleDependencies } | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -1531,6 +1623,39 @@ private void DeleteExtraneousFiles(string packageName, string dirNameVersion) | |
| } | ||
| } | ||
|
|
||
| private bool RetrieveExternalModuleDependenciesForModule(string pkgName, Hashtable moduleMetadata, out string[] externalModuleDependencies, out ErrorRecord error) | ||
| { | ||
| error = null; | ||
| externalModuleDependencies = Utils.EmptyStrArray; | ||
| List<string> externalModuleDependenciesForPkg = new List<string>(); | ||
|
|
||
| Hashtable privateData = moduleMetadata.ContainsKey("PrivateData") ? moduleMetadata["PrivateData"] as Hashtable : new Hashtable(StringComparer.InvariantCultureIgnoreCase); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be OrdinalIgnoreCase |
||
| Hashtable psData = privateData.ContainsKey("PSData") ? privateData["PSData"] as Hashtable : new Hashtable(StringComparer.InvariantCultureIgnoreCase); | ||
| object[] externalModDepObjects = psData.ContainsKey("ExternalModuleDependencies") ? psData["ExternalModuleDependencies"] as object[] : new object[0]; | ||
| if (externalModDepObjects != null) | ||
| { | ||
| foreach (var dep in externalModDepObjects) | ||
| { | ||
| string dependencyName = dep as string; | ||
| if (dependencyName.Contains("=")) | ||
| { | ||
| error = new ErrorRecord( | ||
| new ArgumentException($"Package '{pkgName}' could not be installed: ExternalModuleDependencies should only contain module names, not other metadata. Invalid entry: '{dependencyName}'"), | ||
| "ExternalModuleDependencyInvalidEntry", | ||
| ErrorCategory.ReadError, | ||
| _cmdletPassedIn); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| externalModuleDependenciesForPkg.Add(dependencyName); | ||
| } | ||
| } | ||
|
|
||
| externalModuleDependencies = externalModuleDependenciesForPkg.ToArray(); | ||
| return true; | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
use Utils.EmptyStrArray