From fea4b92ded1a0be42d63f51c12be6ab067dc0bca Mon Sep 17 00:00:00 2001 From: Issac Lin Date: Fri, 24 Jun 2022 22:15:54 +0800 Subject: [PATCH] fix(decompress): Handle split RAR archives (#4994) --- CHANGELOG.md | 1 + lib/decompress.ps1 | 3 +++ test/Scoop-Decompress.Tests.ps1 | 19 ++++++++++++++++++- test/fixtures/decompress/TestCases.zip | Bin 497225 -> 499953 bytes 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d927861a57..9707edd90b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Bug Fixes - **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)) +- **decompress:** Handle split RAR archives ([#4994](https://github.com/ScoopInstaller/Scoop/issues/4994)) - **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)), ([#5006](https://github.com/ScoopInstaller/Scoop/issues/5006)) ### Code Refactoring diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index 3c4f3a9ffb..e7bcfea6cf 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -67,6 +67,9 @@ function Expand-7zipArchive { if (($Path -replace '.*\.([^\.]*)$', '$1') -eq '001') { # Remove splited 7-zip archive parts Get-ChildItem "$($Path -replace '\.[^\.]*$', '').???" | Remove-Item -Force + } elseif (($Path -replace '.*\.part(\d+)\.rar$', '$1')[-1] -eq '1') { + # Remove splitted RAR archive parts + Get-ChildItem "$($Path -replace '\.part(\d+)\.rar$', '').part*.rar" | Remove-Item -Force } else { Remove-Item $Path -Force } diff --git a/test/Scoop-Decompress.Tests.ps1 b/test/Scoop-Decompress.Tests.ps1 index 0bdc20f363..b568ef8e56 100644 --- a/test/Scoop-Decompress.Tests.ps1 +++ b/test/Scoop-Decompress.Tests.ps1 @@ -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 '16507166814dbd02be80c14b737eb6b0245c47439ca3ed308b5625d64babecc8' + compute_hash $testcases 'sha256' | Should -Be '791bfce192917a2ff225dcdd87d23ae5f720b20178d85e68e4b1b56139cf8e6a' if (!$isUnix) { Microsoft.PowerShell.Archive\Expand-Archive $testcases $working_dir } @@ -44,6 +44,9 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test5_1 = "$working_dir\7ZipTest5.7z.001" $test5_2 = "$working_dir\7ZipTest5.7z.002" $test5_3 = "$working_dir\7ZipTest5.7z.003" + $test6_1 = "$working_dir\7ZipTest6.part01.rar" + $test6_2 = "$working_dir\7ZipTest6.part02.rar" + $test6_3 = "$working_dir\7ZipTest6.part03.rar" } It 'extract normal compressed file' -Skip:$isUnix { @@ -81,6 +84,13 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { (Get-ChildItem $to).Count | Should -Be 1 } + It 'extract splited RAR archives (.part01.rar, .part02.rar, ...)' -Skip:$isUnix { + $to = test_extract 'Expand-7zipArchive' $test6_1 + $to | Should -Exist + "$to\dummy" | 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 @@ -92,6 +102,13 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test5_1 | Should -Not -Exist $test5_2 | Should -Not -Exist $test5_3 | Should -Not -Exist + $test6_1 | Should -Exist + $test6_2 | Should -Exist + $test6_3 | Should -Exist + test_extract 'Expand-7zipArchive' $test6_1 $true + $test6_1 | Should -Not -Exist + $test6_2 | Should -Not -Exist + $test6_3 | Should -Not -Exist } } diff --git a/test/fixtures/decompress/TestCases.zip b/test/fixtures/decompress/TestCases.zip index fd5115405aaad83c1b34e3df75d41609a2294a79..12a891eee9e009bad85c1d6acddfd14ec3a4f0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