Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(depends): Avoid digits in archive file extension #4915

Merged
merged 17 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop)

### Bug Fixes

- **depends:** Avoid digits in archive file extension (except for .7z and .001) ([#4915](https://github.com/ScoopInstaller/Scoop/issues/4915))
- **bucket:** Don't check remote URL of non-git buckets ([#4923](https://github.com/ScoopInstaller/Scoop/issues/4923))
- **bucket:** Don't write message OK before bucket is cloned ([#4925](https://github.com/ScoopInstaller/Scoop/issues/4925))

Expand Down
5 changes: 5 additions & 0 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function Expand-7zipArchive {
if ($Removal) {
# Remove original archive file
Remove-Item $Path -Force
if ([System.IO.Path]::GetExtension($Path) -eq '.001') {
# Remove remaining 7-zip archive parts
$FileNameWithoutExt = [System.IO.Path]::GetFileNameWithoutExtension($Path)
Get-ChildItem $([System.IO.Path]::GetDirectoryName($Path)) | Where {$_ -match ([Regex]::Escape($FileNameWithoutExt)+'\.\d{3}$')} | Remove-Item
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/depends.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function Test-7zipRequirement {
$Uri
)
return ($Uri | Where-Object {
$_ -match '\.((gz)|(tar)|(t[abgpx]z2?)|(lzma)|(bz2?)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))(\.[^.]+)?$'
$_ -match '\.((gz)|(tar)|(t[abgpx]z2?)|(lzma)|(bz2?)|(7z)|(001)|(rar)|(iso)|(xz)|(lzh)|(nupkg))(\.[^\d.]+)?$'
}).Count -gt 0
}

Expand Down
19 changes: 18 additions & 1 deletion test/Scoop-Decompress.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 '3a442e85b466833eeafbd08c57d8f51bf7ff041867ee0bdb7db1f12480b3624a'
compute_hash $testcases 'sha256' | Should -Be '16507166814dbd02be80c14b737eb6b0245c47439ca3ed308b5625d64babecc8'
if (!$isUnix) {
Microsoft.PowerShell.Archive\Expand-Archive $testcases $working_dir
}
Expand All @@ -41,6 +41,9 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' {
$test2 = "$working_dir\7ZipTest2.tgz"
$test3 = "$working_dir\7ZipTest3.tar.bz2"
$test4 = "$working_dir\7ZipTest4.tar.gz"
$test5_1 = "$working_dir\7ZipTest5.7z.001"
$test5_2 = "$working_dir\7ZipTest5.7z.002"
$test5_3 = "$working_dir\7ZipTest5.7z.003"
}

It 'extract normal compressed file' -Skip:$isUnix {
Expand Down Expand Up @@ -71,10 +74,24 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' {
(Get-ChildItem $to).Count | Should -Be 1
}

It 'extract splited 7z archives (.001, .002, ...)' -Skip:$isUnix {
$to = test_extract 'Expand-7zipArchive' $test5_1
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}

It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix {
$test1 | Should -Exist
test_extract 'Expand-7zipArchive' $test1 $true
$test1 | Should -Not -Exist
$test5_1 | Should -Exist
$test5_2 | Should -Exist
$test5_3 | Should -Exist
test_extract 'Expand-7zipArchive' $test5_1 $true
$test5_1 | Should -Not -Exist
$test5_2 | Should -Not -Exist
$test5_3 | Should -Not -Exist
}
}

Expand Down
Binary file modified test/fixtures/decompress/TestCases.zip
Binary file not shown.