Skip to content

Commit 913a92e

Browse files
authored
Fix 1659 "Some Nuget packages fail to extract" (#1707)
1 parent 08d5b7a commit 913a92e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/code/InstallHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ private bool TryExtractToDirectory(string zipPath, string extractPath, out Error
12031203
{
12041204
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
12051205
{
1206-
foreach (ZipArchiveEntry entry in archive.Entries)
1206+
foreach (ZipArchiveEntry entry in archive.Entries.Where(entry => entry.CompressedLength > 0))
12071207
{
12081208
// If a file has one or more parent directories.
12091209
if (entry.FullName.Contains(Path.DirectorySeparatorChar) || entry.FullName.Contains(Path.AltDirectorySeparatorChar))

test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
1414
BeforeAll {
1515
$localRepo = "psgettestlocal"
1616
$localUNCRepo = "psgettestlocal3"
17+
$localNupkgRepo = "LocalNupkgRepo"
18+
$localNupkgRepoUri = "test\testFiles\testNupkgs"
1719
$testModuleName = "test_local_mod"
1820
$testModuleName2 = "test_local_mod2"
1921
$testModuleClobber = "testModuleClobber"
2022
$testModuleClobber2 = "testModuleClobber2"
2123
Get-NewPSResourceRepositoryFile
2224
Register-LocalRepos
25+
Register-PSResourceRepository -Name $localNupkgRepo -SourceLocation $localNupkgRepoUri
2326

2427
$prereleaseLabel = "alpha001"
2528
$tags = @()
@@ -279,4 +282,13 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
279282
$err[$i].FullyQualifiedErrorId | Should -Not -Be "System.NullReferenceException,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource"
280283
}
281284
}
285+
286+
It "Install .nupkg that contains directories (specific package throws errors when accessed by ZipFile.OpenRead)" {
287+
$nupkgName = "Microsoft.Web.Webview2"
288+
$nupkgVersion = "1.0.2792.45"
289+
Install-PSResource -Name $nupkgName -Version $nupkgVersion -Repository $localNupkgRepo -TrustRepository
290+
$pkg = Get-InstalledPSResource $nupkgName
291+
$pkg.Name | Should -Be $nupkgName
292+
$pkg.Version | Should -Be $nupkgVersion
293+
}
282294
}
Binary file not shown.

0 commit comments

Comments
 (0)