fix(decompress): Fix nested Zstd archive extraction (#4608)

This commit is contained in:
Hsiao-nan Cheung
2021-12-31 01:04:47 +08:00
committed by GitHub
parent 271d41b949
commit d5cb86078b
5 changed files with 24 additions and 23 deletions
+5
View File
@@ -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))
### Styles
+10 -14
View File
@@ -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
}
}
+4 -4
View File
@@ -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
}
+5 -5
View File
@@ -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'
}
Binary file not shown.