Skip to content

Commit

Permalink
Fix 1659 "Some Nuget packages fail to extract" (#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-l-a-v authored Oct 10, 2024
1 parent 08d5b7a commit 913a92e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ private bool TryExtractToDirectory(string zipPath, string extractPath, out Error
{
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
foreach (ZipArchiveEntry entry in archive.Entries.Where(entry => entry.CompressedLength > 0))
{
// If a file has one or more parent directories.
if (entry.FullName.Contains(Path.DirectorySeparatorChar) || entry.FullName.Contains(Path.AltDirectorySeparatorChar))
Expand Down
12 changes: 12 additions & 0 deletions test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
BeforeAll {
$localRepo = "psgettestlocal"
$localUNCRepo = "psgettestlocal3"
$localNupkgRepo = "LocalNupkgRepo"
$localNupkgRepoUri = "test\testFiles\testNupkgs"
$testModuleName = "test_local_mod"
$testModuleName2 = "test_local_mod2"
$testModuleClobber = "testModuleClobber"
$testModuleClobber2 = "testModuleClobber2"
Get-NewPSResourceRepositoryFile
Register-LocalRepos
Register-PSResourceRepository -Name $localNupkgRepo -SourceLocation $localNupkgRepoUri

$prereleaseLabel = "alpha001"
$tags = @()
Expand Down Expand Up @@ -279,4 +282,13 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
$err[$i].FullyQualifiedErrorId | Should -Not -Be "System.NullReferenceException,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource"
}
}

It "Install .nupkg that contains directories (specific package throws errors when accessed by ZipFile.OpenRead)" {
$nupkgName = "Microsoft.Web.Webview2"
$nupkgVersion = "1.0.2792.45"
Install-PSResource -Name $nupkgName -Version $nupkgVersion -Repository $localNupkgRepo -TrustRepository
$pkg = Get-InstalledPSResource $nupkgName
$pkg.Name | Should -Be $nupkgName
$pkg.Version | Should -Be $nupkgVersion
}
}
Binary file not shown.

0 comments on commit 913a92e

Please sign in to comment.