diff --git a/CHANGELOG.md b/CHANGELOG.md index 996e0f82cc..62ebe2e8d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ### Bug Fixes - **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595)) +- **decompress:** Fix nested Zstd archive extraction ([#4608](https://github.com/ScoopInstaller/Scoop/issues/4608)) + +### Documentation + +- **changelog:** Add 'CHANGLOG.md' ([#4600](https://github.com/ScoopInstaller/Scoop/issues/4600)) ## [2021-12-26] diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index db077d4155..57d0ea57e3 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -137,20 +137,20 @@ function Expand-ZstdArchive { [String] $Switches, [Switch] - $Overwrite, - [Switch] $Removal ) $ZstdPath = Get-HelperPath -Helper Zstd - $LogPath = "$(Split-Path $Path)\zstd.log" - $DestinationPath = $DestinationPath.TrimEnd("\") + $LogPath = Join-Path (Split-Path $Path) 'zstd.log' + $DestinationPath = $DestinationPath.TrimEnd('\') ensure $DestinationPath | Out-Null - $ArgList = @('-d', "`"$Path`"", '--output-dir-flat', "`"$DestinationPath`"", "-v") + $ArgList = @('-d', "`"$Path`"", '--output-dir-flat', "`"$DestinationPath`"", '-f', '-v') + if ($Switches) { $ArgList += (-split $Switches) } - if ($Overwrite) { - $ArgList += '-f' + if ($Removal) { + # Remove original archive file + $ArgList += '--rm' } $Status = Invoke-ExternalCommand $ZstdPath $ArgList -LogPath $LogPath if (!$Status) { @@ -158,19 +158,15 @@ function Expand-ZstdArchive { } $IsTar = (strip_ext $Path) -match '\.tar$' if (!$IsTar -and $ExtractDir) { - movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null + movedir (Join-Path $DestinationPath $ExtractDir) $DestinationPath | Out-Null } if (Test-Path $LogPath) { Remove-Item $LogPath -Force } if ($IsTar) { # Check for tar - $TarFile = (strip_ext $Path) - Expand-7zipArchive -Path "$TarFile" -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal - } - if ($Removal) { - # Remove original archive file - Remove-Item $Path -Force + $TarFile = Join-Path $DestinationPath (Split-Path $Path -LeafBase) + Expand-7zipArchive -Path $TarFile -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal } } diff --git a/test/Scoop-Decompress.Tests.ps1 b/test/Scoop-Decompress.Tests.ps1 index f14c3cf0f6..a80041f6b3 100644 --- a/test/Scoop-Decompress.Tests.ps1 +++ b/test/Scoop-Decompress.Tests.ps1 @@ -19,7 +19,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { It "Decompression test cases should exist" { $testcases = "$working_dir\TestCases.zip" $testcases | Should -Exist - compute_hash $testcases 'sha256' | Should -Be '900b6e05275ad11a57dad85ffac6d9b4995657956a980bb1eae12c173f34a280' + compute_hash $testcases 'sha256' | Should -Be '3a442e85b466833eeafbd08c57d8f51bf7ff041867ee0bdb7db1f12480b3624a' if (!$isUnix) { Microsoft.PowerShell.Archive\Expand-Archive $testcases $working_dir } @@ -91,14 +91,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { It "extract normal compressed file" -Skip:$isUnix { $to = test_extract "Expand-ZstdArchive" $test1 $to | Should -Exist - "$to\empty" | Should -Exist + "$to\ZstdTest" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } It "extract nested compressed file" -Skip:$isUnix { - $to = test_extract "Expand-7zipArchive" $test2 + $to = test_extract "Expand-ZstdArchive" $test2 $to | Should -Exist - "$to\empty" | Should -Exist + "$to\ZstdTest" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } diff --git a/test/bin/test.ps1 b/test/bin/test.ps1 index d84cce3240..ec0662e571 100644 --- a/test/bin/test.ps1 +++ b/test/bin/test.ps1 @@ -1,7 +1,7 @@ -#requires -Version 5.0 -#requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' } -#requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '4.4.0' } -#requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' } +#Requires -Version 5.0 +#Requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' } +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '4.10.1' } +#Requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' } param( [String] $TestPath = 'test/' ) @@ -39,7 +39,7 @@ if ($env:CI -eq $true) { } if ($env:CI_WINDOWS -ne $true) { - Write-Warning "Skipping tests and code linting for decompress.ps1 because they only work on Windows" + Write-Warning 'Skipping tests and code linting for decompress.ps1 because they only work on Windows' $excludes += 'Decompress' } diff --git a/test/fixtures/decompress/TestCases.zip b/test/fixtures/decompress/TestCases.zip index d8905f4c57..fb32e387f7 100644 Binary files a/test/fixtures/decompress/TestCases.zip and b/test/fixtures/decompress/TestCases.zip differ