Skip to content

Commit 3399c73

Browse files
authored
Bugfix for comparing file path name to determine exact match (#1817)
1 parent dbd2fa8 commit 3399c73

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/code/Utils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,24 +1240,24 @@ internal static void GetMetadataFilesFromPath(string dirPath, string packageName
12401240
if (string.Compare($"{packageName}.psd1", fileName, StringComparison.OrdinalIgnoreCase) == 0)
12411241
{
12421242
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
1243+
psd1FilePath = file;
12431244
}
1244-
psd1FilePath = file;
12451245
}
12461246
else if (file.EndsWith("nuspec"))
12471247
{
12481248
if (string.Compare($"{packageName}.nuspec", fileName, StringComparison.OrdinalIgnoreCase) == 0)
12491249
{
12501250
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
1251+
nuspecFilePath = file;
12511252
}
1252-
nuspecFilePath = file;
12531253
}
12541254
else if (file.EndsWith("ps1"))
12551255
{
12561256
if (string.Compare($"{packageName}.ps1", fileName, StringComparison.OrdinalIgnoreCase) == 0)
12571257
{
12581258
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
1259+
ps1FilePath = file;
12591260
}
1260-
ps1FilePath = file;
12611261
}
12621262
}
12631263
}

test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,15 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
337337
$res.Version | Should -Be $nupkgVersion
338338
$res.Prerelease | Should -Be $prereleaseLabel
339339
}
340+
341+
It "find module that has multiple manifests and use exact name match one" {
342+
# Az.KeyVault has 2 manifest files - Az.KeyVault.psd1 and Az.KeyVault.Extension.psd1
343+
# this test was added because PSResourceGet would previously pick the .psd1 file by pattern matching the module name, not exact matching it
344+
# this meant Az.KeyVault.Extension.psd1 and its metadata was being returned.
345+
# The package is present on PSGallery but issue reproduces when looking at the package's file paths in local repo
346+
$PSGalleryName = Get-PSGalleryName
347+
Save-PSResource -Name 'Az.KeyVault' -Version '6.3.1' -Repository $PSGalleryName -AsNupkg -Path $localRepoUriAddress -TrustRepository
348+
$res = Find-PSResource -Name 'Az.KeyVault' -Repository $localRepo
349+
$res.Version | Should -Be "6.3.1"
350+
}
340351
}

0 commit comments

Comments
 (0)