Skip to content

Commit dd44261

Browse files
niheavense35710
authored andcommitted
fix(decompress): Fix nested Zstd archive extraction (ScoopInstaller#4608)
1 parent a0dd6f3 commit dd44261

5 files changed

Lines changed: 24 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
### Bug Fixes
55

66
- **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595))
7+
- **decompress:** Fix nested Zstd archive extraction ([#4608](https://github.com/ScoopInstaller/Scoop/issues/4608))
8+
9+
### Documentation
10+
11+
- **changelog:** Add 'CHANGLOG.md' ([#4600](https://github.com/ScoopInstaller/Scoop/issues/4600))
712

813
### Styles
914

lib/decompress.ps1

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,40 +137,36 @@ function Expand-ZstdArchive {
137137
[String]
138138
$Switches,
139139
[Switch]
140-
$Overwrite,
141-
[Switch]
142140
$Removal
143141
)
144142
$ZstdPath = Get-HelperPath -Helper Zstd
145-
$LogPath = "$(Split-Path $Path)\zstd.log"
146-
$DestinationPath = $DestinationPath.TrimEnd("\")
143+
$LogPath = Join-Path (Split-Path $Path) 'zstd.log'
144+
$DestinationPath = $DestinationPath.TrimEnd('\')
147145
ensure $DestinationPath | Out-Null
148-
$ArgList = @('-d', "`"$Path`"", '--output-dir-flat', "`"$DestinationPath`"", "-v")
146+
$ArgList = @('-d', "`"$Path`"", '--output-dir-flat', "`"$DestinationPath`"", '-f', '-v')
147+
149148
if ($Switches) {
150149
$ArgList += (-split $Switches)
151150
}
152-
if ($Overwrite) {
153-
$ArgList += '-f'
151+
if ($Removal) {
152+
# Remove original archive file
153+
$ArgList += '--rm'
154154
}
155155
$Status = Invoke-ExternalCommand $ZstdPath $ArgList -LogPath $LogPath
156156
if (!$Status) {
157157
abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')"
158158
}
159159
$IsTar = (strip_ext $Path) -match '\.tar$'
160160
if (!$IsTar -and $ExtractDir) {
161-
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
161+
movedir (Join-Path $DestinationPath $ExtractDir) $DestinationPath | Out-Null
162162
}
163163
if (Test-Path $LogPath) {
164164
Remove-Item $LogPath -Force
165165
}
166166
if ($IsTar) {
167167
# Check for tar
168-
$TarFile = (strip_ext $Path)
169-
Expand-7zipArchive -Path "$TarFile" -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal
170-
}
171-
if ($Removal) {
172-
# Remove original archive file
173-
Remove-Item $Path -Force
168+
$TarFile = Join-Path $DestinationPath (Split-Path $Path -LeafBase)
169+
Expand-7zipArchive -Path $TarFile -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal
174170
}
175171
}
176172

test/Scoop-Decompress.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' {
1919
It "Decompression test cases should exist" {
2020
$testcases = "$working_dir\TestCases.zip"
2121
$testcases | Should -Exist
22-
compute_hash $testcases 'sha256' | Should -Be '900b6e05275ad11a57dad85ffac6d9b4995657956a980bb1eae12c173f34a280'
22+
compute_hash $testcases 'sha256' | Should -Be '3a442e85b466833eeafbd08c57d8f51bf7ff041867ee0bdb7db1f12480b3624a'
2323
if (!$isUnix) {
2424
Microsoft.PowerShell.Archive\Expand-Archive $testcases $working_dir
2525
}
@@ -91,14 +91,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' {
9191
It "extract normal compressed file" -Skip:$isUnix {
9292
$to = test_extract "Expand-ZstdArchive" $test1
9393
$to | Should -Exist
94-
"$to\empty" | Should -Exist
94+
"$to\ZstdTest" | Should -Exist
9595
(Get-ChildItem $to).Count | Should -Be 1
9696
}
9797

9898
It "extract nested compressed file" -Skip:$isUnix {
99-
$to = test_extract "Expand-7zipArchive" $test2
99+
$to = test_extract "Expand-ZstdArchive" $test2
100100
$to | Should -Exist
101-
"$to\empty" | Should -Exist
101+
"$to\ZstdTest" | Should -Exist
102102
(Get-ChildItem $to).Count | Should -Be 1
103103
}
104104

test/bin/test.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#requires -Version 5.0
2-
#requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' }
3-
#requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '4.4.0' }
4-
#requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' }
1+
#Requires -Version 5.0
2+
#Requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' }
3+
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '4.10.1' }
4+
#Requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' }
55
param(
66
[String] $TestPath = 'test/'
77
)
@@ -39,7 +39,7 @@ if ($env:CI -eq $true) {
3939
}
4040

4141
if ($env:CI_WINDOWS -ne $true) {
42-
Write-Warning "Skipping tests and code linting for decompress.ps1 because they only work on Windows"
42+
Write-Warning 'Skipping tests and code linting for decompress.ps1 because they only work on Windows'
4343
$excludes += 'Decompress'
4444
}
4545

-283 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)