Skip to content

Commit 4e3c8f2

Browse files
alericksonCopilot
andcommitted
code clean up
Co-authored-by: Copilot <copilot@github.com>
1 parent 1fd5cee commit 4e3c8f2

8 files changed

Lines changed: 139 additions & 216 deletions

src/code/InstallHelper.cs

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -599,18 +599,6 @@ private List<PSResourceInfo> InstallPackages(
599599

600600
// Add each pkg to _packagesOnMachine (ie pkgs fully installed on the machine).
601601
_packagesOnMachine.Add($"{pkgName}{pkgInfo["pkgVersion"]}");
602-
603-
// PSResourceInfo psResourceInfoPkg = pkgInfo["psResourceInfoPkg"] as PSResourceInfo;
604-
// psResourceInfoPkg.AdditionalMetadata.TryGetValue("NormalizedVersion", out string pkgVersion);
605-
// if (pkgVersion == null)
606-
// {
607-
// // Not all NuGet providers (e.g. Artifactory, possibly others) send NormalizedVersion in NuGet package responses.
608-
// // If they don't, we need to manually construct the combined version+prerelease from pkgToInstall.Version and the prerelease string.
609-
// // Get three digit normalized version
610-
// pkgVersion = Utils.GetThreeDigitNormalizedVersionString(psResourceInfoPkg.Version.ToString(), psResourceInfoPkg.Prerelease);
611-
// }
612-
613-
//_packagesOnMachine.Add($"{pkgName}{pkgVersion}");
614602
}
615603
}
616604
}
@@ -783,47 +771,40 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
783771

784772
// -WhatIf processing.
785773
// TODO::
786-
// if (_savePkg && !_cmdletPassedIn.ShouldProcess($"Package to save: '{pkgToInstall.Name}', version: '{pkgVersion}'"))
787-
// {
788-
789-
790-
// if (!updatedPackagesHash.ContainsKey(pkgToInstall.Name))
791-
// {
792-
793-
// _cmdletPassedIn.WriteDebug($"BeginPackageInstall() - line 784");
794-
// updatedPackagesHash.TryAdd(pkgToInstall.Name, new Hashtable(StringComparer.InvariantCultureIgnoreCase)
795-
// {
796-
// { "isModule", "" },
797-
// { "isScript", "" },
798-
// { "psResourceInfoPkg", pkgToInstall },
799-
// { "tempDirNameVersionPath", tempInstallPath },
800-
// { "pkgVersion", "" },
801-
// { "scriptPath", "" },
802-
// { "installPath", "" }
803-
// });
804-
// }
805-
// }
806-
// else if (!_cmdletPassedIn.ShouldProcess($"Package to install: '{pkgToInstall.Name}', version: '{pkgVersion}'"))
807-
// {
808-
809-
810-
811-
// if (!updatedPackagesHash.ContainsKey(pkgToInstall.Name))
812-
// {
813-
// updatedPackagesHash.TryAdd(pkgToInstall.Name, new Hashtable(StringComparer.InvariantCultureIgnoreCase)
814-
// {
815-
// { "isModule", "" },
816-
// { "isScript", "" },
817-
// { "psResourceInfoPkg", pkgToInstall },
818-
// { "tempDirNameVersionPath", tempInstallPath },
819-
// { "pkgVersion", "" },
820-
// { "scriptPath", "" },
821-
// { "installPath", "" }
822-
// });
823-
// }
824-
// }
825-
//else
826-
//{
774+
if (_savePkg && !_cmdletPassedIn.ShouldProcess($"Package to save: '{pkgToInstall.Name}', version: '{pkgVersion}'"))
775+
{
776+
if (!updatedPackagesHash.ContainsKey(pkgToInstall.Name))
777+
{
778+
updatedPackagesHash.TryAdd(pkgToInstall.Name, new Hashtable(StringComparer.InvariantCultureIgnoreCase)
779+
{
780+
{ "isModule", "" },
781+
{ "isScript", "" },
782+
{ "psResourceInfoPkg", pkgToInstall },
783+
{ "tempDirNameVersionPath", tempInstallPath },
784+
{ "pkgVersion", "" },
785+
{ "scriptPath", "" },
786+
{ "installPath", "" }
787+
});
788+
}
789+
}
790+
else if (!_cmdletPassedIn.ShouldProcess($"Package to install: '{pkgToInstall.Name}', version: '{pkgVersion}'"))
791+
{
792+
if (!updatedPackagesHash.ContainsKey(pkgToInstall.Name))
793+
{
794+
updatedPackagesHash.TryAdd(pkgToInstall.Name, new Hashtable(StringComparer.InvariantCultureIgnoreCase)
795+
{
796+
{ "isModule", "" },
797+
{ "isScript", "" },
798+
{ "psResourceInfoPkg", pkgToInstall },
799+
{ "tempDirNameVersionPath", tempInstallPath },
800+
{ "pkgVersion", "" },
801+
{ "scriptPath", "" },
802+
{ "installPath", "" }
803+
});
804+
}
805+
}
806+
else
807+
{
827808
// Concurrent updates, currently only implemented for v2 server repositories
828809
// Find all dependencies
829810
if (!skipDependencyCheck)
@@ -860,7 +841,7 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
860841
return packagesHash;
861842
}
862843
}
863-
//}
844+
}
864845

865846
return updatedPackagesHash;
866847
}
@@ -902,8 +883,6 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
902883
bool installedToTempPathSuccessfully = _asNupkg ? TrySaveNupkgToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, errorMsgs, warningMsgs, debugMsgs, verboseMsgs) :
903884
TryInstallToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
904885

905-
//Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
906-
907886
if (!installedToTempPathSuccessfully)
908887
{
909888
verboseMsgs.Enqueue($"Failed to install '{depPkgName}' to temp path");
@@ -1149,7 +1128,8 @@ private bool TryInstallToTempPath(
11491128
// This package is not a PowerShell package (eg a resource from the NuGet Gallery).
11501129
installPath = _pathsToInstallPkg.Find(path => path.EndsWith("Modules", StringComparison.InvariantCultureIgnoreCase));
11511130

1152-
// TODO:: _cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}.");
1131+
// TODO: pass in ConcurrentQueue to write out verbose message.
1132+
// _cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}.");
11531133
isModule = true;
11541134
}
11551135

@@ -1507,6 +1487,7 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
15071487
/// </summary>
15081488
private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, out ErrorRecord error)
15091489
{
1490+
// TODO: pass in ConcurrentQueue to write out debug message.
15101491
//_cmdletPassedIn.WriteDebug("In InstallHelper::DetectClobber()");
15111492
error = null;
15121493
bool foundClobber = false;
@@ -1600,6 +1581,7 @@ private bool CreateMetadataXMLFile(string dirNameVersion, string installPath, PS
16001581
/// </summary>
16011582
private void DeleteExtraneousFiles(string packageName, string dirNameVersion)
16021583
{
1584+
// TODO: pass in ConcurrentQueue to write out debug message.
16031585
// _cmdletPassedIn.WriteDebug("In InstallHelper::DeleteExtraneousFiles()");
16041586
// Deleting .nupkg SHA file, .nuspec, and .nupkg after unpacking the module
16051587
// since we download as .zip for HTTP calls, we shouldn't have .nupkg* files

0 commit comments

Comments
 (0)