Skip to content
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- **decompress:** Fix nested Zstd archive extraction ([#4608](https://github.com/ScoopInstaller/Scoop/issues/4608))
- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))

### Code Refactoring

- **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638))

### Builds

- **checkver:** Fix output with '-Version' ([#3774](https://github.com/ScoopInstaller/Scoop/issues/3774))
Expand Down
2 changes: 1 addition & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function app_status($app, $global) {
}

$status.missing_deps = @()
$deps = @(runtime_deps $manifest) | Where-Object {
$deps = @($manifest.depends) | Where-Object {
$app, $bucket, $null = parse_app $_
return !(installed $app)
}
Expand Down
124 changes: 11 additions & 113 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
function Test-7zipRequirement {
[CmdletBinding(DefaultParameterSetName = "URL")]
[OutputType([Boolean])]
param (
[Parameter(Mandatory = $true, ParameterSetName = "URL")]
[String[]]
$URL,
[Parameter(Mandatory = $true, ParameterSetName = "File")]
[String]
$File
)
if ($URL) {
if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) {
return $false
} else {
return ($URL | Where-Object { Test-7zipRequirement -File $_ }).Count -gt 0
}
} else {
return $File -match '\.((gz)|(tar)|(t[abgpx]z2?)|(lzma)|(bz2?)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))(\.[^.]+)?$'
}
}

function Test-ZstdRequirement {
[CmdletBinding(DefaultParameterSetName = "URL")]
[OutputType([Boolean])]
param (
[Parameter(Mandatory = $true, ParameterSetName = "URL")]
[String[]]
$URL,
[Parameter(Mandatory = $true, ParameterSetName = "File")]
[String]
$File
)
if ($URL) {
return ($URL | Where-Object { Test-ZstdRequirement -File $_ }).Count -gt 0
} else {
return $File -match '\.zst$'
}
}

function Test-LessmsiRequirement {
[CmdletBinding()]
[OutputType([Boolean])]
param (
[Parameter(Mandatory = $true)]
[String[]]
$URL
)
if ((get_config MSIEXTRACT_USE_LESSMSI)) {
return ($URL | Where-Object { $_ -match '\.msi$' }).Count -gt 0
} else {
return $false
}
}

function Expand-7zipArchive {
[CmdletBinding()]
param (
Expand All @@ -67,17 +12,17 @@ function Expand-7zipArchive {
[Parameter(ValueFromRemainingArguments = $true)]
[String]
$Switches,
[ValidateSet("All", "Skip", "Rename")]
[ValidateSet('All', 'Skip', 'Rename')]
[String]
$Overwrite,
[Switch]
$Removal
)
if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) {
try {
$7zPath = (Get-Command '7z' -CommandType Application | Select-Object -First 1).Source
$7zPath = (Get-Command '7z' -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source
} catch [System.Management.Automation.CommandNotFoundException] {
abort "Cannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7-Zip manually and try again."
abort "`nCannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7-Zip manually and try again."
}
} else {
$7zPath = Get-HelperPath -Helper 7zip
Expand All @@ -92,9 +37,9 @@ function Expand-7zipArchive {
$ArgList += (-split $Switches)
}
switch ($Overwrite) {
"All" { $ArgList += "-aoa" }
"Skip" { $ArgList += "-aos" }
"Rename" { $ArgList += "-aou" }
'All' { $ArgList += '-aoa' }
'Skip' { $ArgList += '-aos' }
'Rename' { $ArgList += '-aou' }
}
$Status = Invoke-ExternalCommand $7zPath $ArgList -LogPath $LogPath
if (!$Status) {
Expand Down Expand Up @@ -187,7 +132,7 @@ function Expand-MsiArchive {
[Switch]
$Removal
)
$DestinationPath = $DestinationPath.TrimEnd("\")
$DestinationPath = $DestinationPath.TrimEnd('\')
if ($ExtractDir) {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
Expand Down Expand Up @@ -248,9 +193,9 @@ function Expand-InnoArchive {
$LogPath = "$(Split-Path $Path)\innounp.log"
$ArgList = @('-x', "-d`"$DestinationPath`"", "`"$Path`"", '-y')
switch -Regex ($ExtractDir) {
"^[^{].*" { $ArgList += "-c{app}\$ExtractDir" }
"^{.*" { $ArgList += "-c$ExtractDir" }
Default { $ArgList += "-c{app}" }
'^[^{].*' { $ArgList += "-c{app}\$ExtractDir" }
'^{.*' { $ArgList += "-c$ExtractDir" }
Default { $ArgList += '-c{app}' }
}
if ($Switches) {
$ArgList += (-split $Switches)
Expand Down Expand Up @@ -286,34 +231,7 @@ function Expand-ZipArchive {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
# All methods to unzip the file require .NET4.5+
if ($PSVersionTable.PSVersion.Major -lt 5) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
try {
[System.IO.Compression.ZipFile]::ExtractToDirectory($Path, $DestinationPath)
} catch [System.IO.PathTooLongException] {
# try to fall back to 7zip if path is too long
if (Test-HelperInstalled -Helper 7zip) {
Expand-7zipArchive $Path $DestinationPath -Removal
return
} else {
abort "Unzip failed: Windows can't handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again."
}
} catch [System.IO.IOException] {
if (Test-HelperInstalled -Helper 7zip) {
Expand-7zipArchive $Path $DestinationPath -Removal
return
} else {
abort "Unzip failed: Windows can't handle the file names in this zip file.`nRun 'scoop install 7zip' and try again."
}
} catch {
abort "Unzip failed: $_"
}
} else {
# Use Expand-Archive to unzip in PowerShell 5+
# Compatible with Pscx (https://github.com/Pscx/Pscx)
Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
}
Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
Comment thread
niheaven marked this conversation as resolved.
if ($ExtractDir) {
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
Expand Down Expand Up @@ -356,23 +274,3 @@ function Expand-DarkArchive {
Remove-Item $Path -Force
}
}

function extract_7zip($path, $to, $removal) {
Show-DeprecatedWarning $MyInvocation 'Expand-7zipArchive'
Expand-7zipArchive -Path $path -DestinationPath $to -Removal:$removal @args
}

function extract_msi($path, $to, $removal) {
Show-DeprecatedWarning $MyInvocation 'Expand-MsiArchive'
Expand-MsiArchive -Path $path -DestinationPath $to -Removal:$removal
}

function unpack_inno($path, $to, $removal) {
Show-DeprecatedWarning $MyInvocation 'Expand-InnoArchive'
Expand-InnoArchive -Path $path -DestinationPath $to -Removal:$removal @args
}

function extract_zip($path, $to, $removal) {
Show-DeprecatedWarning $MyInvocation 'Expand-ZipArchive'
Expand-ZipArchive -Path $path -DestinationPath $to -Removal:$removal
}
Loading