Skip to content

Commit 53b9d72

Browse files
committed
Add bug fix for retrieving pkg name from local repos
1 parent 51d46f5 commit 53b9d72

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

src/code/InstallHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ private Hashtable BeginPackageInstall(
737737
FindResults responses = null;
738738
errRecord = null;
739739

740+
//_cmdletPassedIn.WriteWarning($"~~~~~~~~~~~~~~~~~~ pkgNameToInstall is: '{pkgNameToInstall}'.");
741+
740742
switch (searchVersionType)
741743
{
742744
case VersionType.VersionRange:
@@ -813,6 +815,9 @@ private Hashtable BeginPackageInstall(
813815
{
814816
return packagesHash;
815817
}
818+
819+
// THIS SHOULD BE THE CORRECT PKG NAME
820+
// _cmdletPassedIn.WriteWarning($"~~~~~~~~~~~~~~~~~~ pkgToInstall.Name is: '{pkgToInstall.Name}'.");
816821

817822
pkgToInstall.RepositorySourceLocation = repository.Uri.ToString();
818823
pkgToInstall.AdditionalMetadata.TryGetValue("NormalizedVersion", out string pkgVersion);

src/code/LocalServerApiCalls.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private Hashtable GetMetadataFromNupkg(string packageName, string packagePath, s
685685
string psd1FilePath = String.Empty;
686686
string ps1FilePath = String.Empty;
687687
string nuspecFilePath = String.Empty;
688-
Utils.GetMetadataFilesFromPath(tempDiscoveryPath, packageName, out psd1FilePath, out ps1FilePath, out nuspecFilePath);
688+
Utils.GetMetadataFilesFromPath(tempDiscoveryPath, packageName, out psd1FilePath, out ps1FilePath, out nuspecFilePath, out string properCasingPkgName);
689689

690690
List<string> pkgTags = new List<string>();
691691

@@ -710,7 +710,7 @@ private Hashtable GetMetadataFromNupkg(string packageName, string packagePath, s
710710
pkgMetadata.Add("ProjectUri", projectUri);
711711
pkgMetadata.Add("IconUri", iconUri);
712712
pkgMetadata.Add("ReleaseNotes", releaseNotes);
713-
pkgMetadata.Add("Id", packageName);
713+
pkgMetadata.Add("Id", properCasingPkgName);
714714
pkgMetadata.Add(_fileTypeKey, Utils.MetadataFileType.ModuleManifest);
715715

716716
pkgTags.AddRange(pkgHashTags);

src/code/Utils.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,11 +1172,12 @@ internal static HashSet<string> GetInstalledPackages(List<string> pathsToSearch,
11721172
return pkgsInstalledOnMachine;
11731173
}
11741174

1175-
internal static void GetMetadataFilesFromPath(string dirPath, string packageName, out string psd1FilePath, out string ps1FilePath, out string nuspecFilePath)
1175+
internal static void GetMetadataFilesFromPath(string dirPath, string packageName, out string psd1FilePath, out string ps1FilePath, out string nuspecFilePath, out string properCasingPkgName)
11761176
{
11771177
psd1FilePath = String.Empty;
11781178
ps1FilePath = String.Empty;
11791179
nuspecFilePath = String.Empty;
1180+
properCasingPkgName = packageName;
11801181

11811182
var discoveredFiles = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
11821183
string pkgNamePattern = $"{packageName}*";
@@ -1187,14 +1188,26 @@ internal static void GetMetadataFilesFromPath(string dirPath, string packageName
11871188
{
11881189
if (file.EndsWith("psd1"))
11891190
{
1191+
if (string.Compare($"{packageName}.psd1", file, StringComparison.OrdinalIgnoreCase) == 0)
1192+
{
1193+
properCasingPkgName = file.Split(new string[] { ".psd1" }, StringSplitOptions.None).First();
1194+
}
11901195
psd1FilePath = file;
11911196
}
11921197
else if (file.EndsWith("nuspec"))
11931198
{
1199+
if (string.Compare($"{packageName}.nuspec", file, StringComparison.OrdinalIgnoreCase) == 0)
1200+
{
1201+
properCasingPkgName = file.Split(new string[] { ".nuspec" }, StringSplitOptions.None).First();
1202+
}
11941203
nuspecFilePath = file;
11951204
}
11961205
else if (file.EndsWith("ps1"))
11971206
{
1207+
if (string.Compare($"{packageName}.ps1", file, StringComparison.OrdinalIgnoreCase) == 0)
1208+
{
1209+
properCasingPkgName = file.Split(new string[] { ".ps1" }, StringSplitOptions.None).First();
1210+
}
11981211
ps1FilePath = file;
11991212
}
12001213
}

test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,30 +141,10 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
141141

142142
It "Install resource with cmdlet names from a module already installed with -NoClobber (should not clobber)" {
143143
Install-PSResource -Name $testModuleClobber -Repository $localRepo -TrustRepository -Verbose
144-
145-
Write-Verbose -Verbose "~~~~~~~~~~~~~~~"
146-
Get-ChildItem $localRepo -Recurse
147-
Write-Verbose -Verbose "~~~~~~~~~~~~~~~"
148-
149144
$pkg = Get-InstalledPSResource $testModuleClobber
150145
$pkg.Name | Should -Be $testModuleClobber
151146
$pkg.Version | Should -Be "1.0.0"
152147

153-
154-
# Get the first available module named 'clobbertestmodule1' and its exported commands
155-
$module = (Get-Module -ListAvailable $testModuleClobber)
156-
Write-Verbose -Verbose "Module Name: $($module.Name)"
157-
$moduleIdx = $module[0]
158-
159-
# Iterate through each exported command in the module
160-
foreach ($command in $moduleIdx.ExportedCommands.Values) {
161-
# Output the command's name and details
162-
Write-Verbose -Verbose "Command Name: $($command.Name)"
163-
Write-Verbose -Verbose "Command Type: $($command.CommandType)"
164-
Write-Verbose -Verbose "----------------------------------"
165-
}
166-
167-
168148
Install-PSResource -Name $testModuleClobber2 -Repository $localRepo -TrustRepository -NoClobber -ErrorVariable ev -ErrorAction SilentlyContinue -verbose
169149
$pkg = Get-InstalledPSResource $testModuleClobber2 -ErrorAction SilentlyContinue
170150

0 commit comments

Comments
 (0)