Skip to content

Commit

Permalink
chore: Cleanup unused functions (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Dec 25, 2021
1 parent fc30fd8 commit 6154d76
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 147 deletions.
2 changes: 1 addition & 1 deletion lib/Alias.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Get-ScoopAliasPath {
)

begin {
if (($null -eq $AliasName) -or ($AliasName -eq '')) { throw [ScoopException] 'Alias name required' }
if (($null -eq $AliasName) -or ($AliasName -eq '')) { throw [ScoopException]::new('Alias name required') }
}

process { return shimdir $false | Join-Path -ChildPath "scoop-$AliasName.ps1" }
Expand Down
4 changes: 2 additions & 2 deletions lib/Applications.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Set-InstalledApplicationInformationPropertyValue {
$info = if ($InputObject) { $InputObject } else { Get-InstalledApplicationInformation -AppName $AppName -Version $Version -Global:$Global }
if (!$info) { $info = @{ } }
if ($Property.Count -ne $Value.Count) {
throw [ScoopException] 'Property and value mismatch'
throw [ScoopException]::new('Property and value mismatch')
}
}

Expand All @@ -149,7 +149,7 @@ function Set-InstalledApplicationInformationPropertyValue {
if ($Force) {
$info.$prop = $val
} else {
throw [ScoopException] "Property '$prop' is already set"
throw [ScoopException]::new("Property '$prop' is already set")
}
} else {
$info | Add-Member -MemberType 'NoteProperty' -Name $prop -Value $val
Expand Down
4 changes: 2 additions & 2 deletions lib/Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function Resolve-SpecificQueryDependency {
try {
$information = Resolve-ManifestInformation -ApplicationQuery $ApplicationQuery
} catch {
throw [ScoopException] "'$ApplicationQuery' -> $($_.Exception.Message)"
throw [ScoopException]::new("'$ApplicationQuery' -> $($_.Exception.Message)")
}
}

Expand All @@ -171,7 +171,7 @@ function Resolve-SpecificQueryDependency {
foreach ($dep in $deps) {
if ($Resolved.ApplicationName -notcontains $dep) {
if ($Unresolved -contains $dep) {
throw [ScoopException] "Circular dependency detected: '$($information.ApplicationName)' -> '$dep'." # TerminatingError thrown
throw [ScoopException]::new("Circular dependency detected: '$($information.ApplicationName)' -> '$dep'.") # TerminatingError thrown
}

Resolve-SpecificQueryDependency -ApplicationQuery $dep -Architecture $Architecture -Resolved $Resolved -Unresolved $Unresolved -IncludeInstalled:$IncludeInstalled
Expand Down
4 changes: 2 additions & 2 deletions lib/Installation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Install-ScoopApplication {
$version = $ResolvedObject.ManifestObject.version

if ($version -match '[^\w\.\-\+_]') {
throw [ScoopException] "Invalid manifest|-Manifest version has unsupported character '$($matches[0])'." # TerminatingError thrown
throw [ScoopException]::new("Invalid manifest|-Manifest version has unsupported character '$($matches[0])'.") # TerminatingError thrown
}

if ($version -eq 'nightly') {
Expand All @@ -29,7 +29,7 @@ function Install-ScoopApplication {
}

if (!(supports_architecture $manifest $Architecture)) {
throw [ScoopException] "'$appName' does not support $Architecture architecture" # TerminatingError thrown
throw [ScoopException]::new("'$appName' does not support $Architecture architecture") # TerminatingError thrown
}

Deny-ArmInstallation -Manifest $manifest -Architecture $architecture
Expand Down
6 changes: 3 additions & 3 deletions lib/ManifestHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function Assert-Administrator {
.SYNOPSIS
Test administrator privileges.
#>
if (!(is_admin)) { throw [ScoopException] 'Administrator privileges are required' }
if (!(is_admin)) { throw [ScoopException]::new('Administrator privileges are required') }
}

function Assert-WindowsMinimalVersion {
Expand All @@ -202,7 +202,7 @@ function Assert-WindowsMinimalVersion {

$cmp = Compare-Version -ReferenceVersion ([Environment]::OSVersion.Version.ToString()) -DifferenceVersion $Version
if ($cmp -eq 1) {
throw [ScoopException] "Application requires at least '$Version' Windows version"
throw [ScoopException]::new("Application requires at least '$Version' Windows version")
}
}

Expand All @@ -221,7 +221,7 @@ function Assert-ScoopConfigValue {

process {
$actualValue = get_config $ConfigOption
if ($actualValue -ne $ExpectedValue) { throw [ScoopException] "Configuration option '$ConfigOption' needs to be set to '$ExpectedValue'" }
if ($actualValue -ne $ExpectedValue) { throw [ScoopException]::new("Configuration option '$ConfigOption' needs to be set to '$ExpectedValue'") }
}
}
#endregion Asserts
14 changes: 7 additions & 7 deletions lib/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ function Update-App {
try {
$ar = Resolve-ManifestInformation -ApplicationQuery $a
} catch {
throw [ScoopException] $_.Exception.Message # TerminatingError thrown
throw [ScoopException]::new($_.Exception.Message) # TerminatingError thrown
}
$toInstall.Resolved += $ar
} else {
$toInstall = Resolve-MultipleApplicationDependency -Applications @($a) -Architecture $architecture -IncludeInstalledApps
}

if ($toInstall.Failed.Count -gt 0) {
throw [ScoopException] 'Cannot resolve all dependencies' # TerminatingError thrown
throw [ScoopException]::new('Cannot resolve all dependencies') # TerminatingError thrown
}

$_deps = @($toInstall.Resolved | Where-Object -Property 'Dependency' -NE -Value $false)
Expand All @@ -330,18 +330,18 @@ function Update-App {

# TODO: Could this ever happen?
if (!$Force -and ($oldVersion -eq $version)) {
throw [ScoopException] "The Latest version of '$App' ($version) is already installed." # TerminatingError thrown
throw [ScoopException]::new("The Latest version of '$App' ($version) is already installed.") # TerminatingError thrown
}

# TODO:???
# TODO: Case when bucket no longer have this application?
if (!$version) {
throw [ScoopException] "No manifest available for '$App'" # TerminatingError thrown
throw [ScoopException]::new("No manifest available for '$App'") # TerminatingError thrown
}

# Do not update if the new manifest does not support the installed architecture
if (!(supports_architecture $manifest $architecture)) {
throw [ScoopException] "Manifest no longer supports specific architecture '$architecture'" # TerminatingError thrown
throw [ScoopException]::new("Manifest no longer supports specific architecture '$architecture'") # TerminatingError thrown
}

Deny-ArmInstallation -Manifest $manifest -Architecture $architecture
Expand Down Expand Up @@ -373,7 +373,7 @@ function Update-App {
if ($url -like '*sourceforge.net*') {
Write-UserMessage -Message 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.' -Warning
}
throw [ScoopException] "Hash check failed|-$err" # TerminatingError thrown
throw [ScoopException]::new("Hash check failed|-$err") # TerminatingError thrown
}
}
}
Expand All @@ -384,7 +384,7 @@ function Update-App {
#endregion Workaround of #2220

$result = Uninstall-ScoopApplication -App $App -Global:$Global
if ($result -eq $false) { throw [ScoopException] 'Ignore' }
if ($result -eq $false) { throw [ScoopException]::new('Ignore') }

# Rename current version to .old if same version is installed
if ($Force -and ($oldVersion -eq $version)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function command_path($cmd) {
# Get path from shim
$shim_path = Join-Path $SCOOP_ROOT_DIRECTORY "shims\scoop-$cmd.ps1"
if (!(Test-Path -LiteralPath $shim_path)) {
throw [ScoopException] "Shim for alias '$cmd' does not exist" # TerminatingError thrown
throw [ScoopException]::new("Shim for alias '$cmd' does not exist") # TerminatingError thrown
}

$cmd_path = $shim_path
Expand Down
8 changes: 5 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ function debug($obj) {
Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -ForegroundColor 'DarkGray'
}
}
function success($msg) { Write-Host $msg -ForegroundColor 'DarkGreen' }

function filesize($length) {
$gb = [System.Math]::Pow(2, 30)
Expand Down Expand Up @@ -624,7 +623,7 @@ function movedir {

if ($proc.ExitCode -ge 8) {
debug $out
throw [ScoopException] "Decompress Error|-Could not find '$(fname $from) in $parent'! (error $($proc.ExitCode))" # TerminatingError thrown
throw [ScoopException]::new("Decompress Error|-Could not find '$(fname $from) in $parent'! (error $($proc.ExitCode))") # TerminatingError thrown
}

# Wait for robocopy to terminate its threads
Expand Down Expand Up @@ -662,7 +661,7 @@ function warn_on_overwrite($shim_ps1, $path) {
}

function shim($path, $global, $name, $arg) {
if (!(Test-Path $path)) { throw [ScoopException] "Shim creation fail|-Cannot shim '$(fname $path)': could not find '$path'" } # TerminatingError thrown
if (!(Test-Path $path)) { throw [ScoopException]::new("Shim creation fail|-Cannot shim '$(fname $path)': could not find '$path'") } # TerminatingError thrown

$abs_shimdir = shimdir $global | Confirm-DirectoryExistence
if (!$name) { $name = strip_ext (fname $path) }
Expand Down Expand Up @@ -985,8 +984,10 @@ function error($msg) { Write-UserMessage -Message $msg -Err }
function warn($msg) { Write-UserMessage -Message $msg -Warning }
function info($msg) { Write-UserMessage -Message $msg -Info }
function message($msg) { Write-UserMessage -Message $msg -SkipSeverity }
function success($msg) { Write-UserMessage -Message $msg -Success }
#endregion Deprecated

#region Main
##################
# Core Bootstrap #
##################
Expand Down Expand Up @@ -1054,3 +1055,4 @@ $PSNativeCommandArgumentPassing = 'Legacy'

# Setup proxy globally
setup_proxy
#endregion Main
31 changes: 16 additions & 15 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ function Expand-7zipArchive {
try {
$7zPath = (Get-Command '7z' -CommandType 'Application' -ErrorAction 'Stop' | Select-Object -First 1).Source
} catch [System.Management.Automation.CommandNotFoundException] {
throw [ScoopException] (
"Cannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!",
"Run 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7zip manually and try again." -join "`n"
throw [ScoopException]::new((
"Cannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!",
"Run 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7zip manually and try again." -join "`n"
)
) # TerminatingError thrown
}
} else {
Expand All @@ -155,11 +156,11 @@ function Expand-7zipArchive {
try {
$status = Invoke-ExternalCommand $7zPath $argList -LogPath $logPath
} catch [System.Management.Automation.ParameterBindingException] {
throw [ScoopException] '''7zip'' is not installed or cannot be used' # TerminatingError thrown
throw [ScoopException]::new('''7zip'' is not installed or cannot be used') # TerminatingError thrown
}

if (!$status) {
throw [ScoopException] (_decompressErrorPrompt $Path $logPath) # TerminatingError thrown
throw [ScoopException]::new((_decompressErrorPrompt $Path $logPath)) # TerminatingError thrown
}
if (!$isTar -and $ExtractDir) {
movedir (Join-Path $DestinationPath $ExtractDir) $DestinationPath | Out-Null
Expand All @@ -174,7 +175,7 @@ function Expand-7zipArchive {
$tarFile = (Get-Content -Path $logPath)[-4] -replace '.{53}(.*)', '$1'
Expand-7zipArchive -Path (Join-Path $DestinationPath $tarFile) -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal
} else {
throw [ScoopException] "Decompress error|-Failed to list files in $Path.`nNot a 7zip supported archive file." # TerminatingError thrown
throw [ScoopException]::new("Decompress error|-Failed to list files in $Path.`nNot a 7zip supported archive file.") # TerminatingError thrown
}
}

Expand Down Expand Up @@ -232,7 +233,7 @@ function Expand-MsiArchive {
$status = Invoke-ExternalCommand $msiPath $argList -LogPath $logPath

if (!$status) {
throw [ScoopException] (_decompressErrorPrompt $Path $logPath) # TerminatingError thrown
throw [ScoopException]::new((_decompressErrorPrompt $Path $logPath)) # TerminatingError thrown
}

$sourceDir = Join-Path $DestinationPath 'SourceDir'
Expand Down Expand Up @@ -330,11 +331,11 @@ function Expand-InnoArchive {
try {
$status = Invoke-ExternalCommand $innoPath $argList -LogPath $logPath
} catch [System.Management.Automation.ParameterBindingException] {
throw [ScoopException] "'$inno' is not installed or cannot be used" # TerminatingError thrown
throw [ScoopException]::new("'$inno' is not installed or cannot be used") # TerminatingError thrown
}

if (!$status) {
throw [ScoopException] (_decompressErrorPrompt $Path $logPath) # TerminatingError thrown
throw [ScoopException]::new((_decompressErrorPrompt $Path $logPath)) # TerminatingError thrown
}

# Innoextract --include do not extract the directory, it only filter the content
Expand Down Expand Up @@ -389,17 +390,17 @@ function Expand-ZipArchive {
Expand-7zipArchive $Path $DestinationPath -Removal:$Removal
return
} else {
throw [ScoopException] "Unzip failed: Windows cannot handle long paths in this zip file.`nInstall 7zip and try again." # TerminatingError thrown
throw [ScoopException]::new("Unzip failed: Windows cannot handle long paths in this zip file.`nInstall 7zip and try again.") # TerminatingError thrown
}
} catch [System.IO.IOException] {
if (Test-HelperInstalled -Helper '7zip') {
Expand-7zipArchive $Path $DestinationPath -Removal:$Removal
return
} else {
throw [ScoopException] "Unzip failed: Windows cannot handle the file names in this zip file.`nInstall 7zip and try again." # TerminatingError thrown
throw [ScoopException]::new("Unzip failed: Windows cannot handle the file names in this zip file.`nInstall 7zip and try again.") # TerminatingError thrown
}
} catch {
throw [ScoopException] "Decompress error|-Unzip failed: $_" # TerminatingError thrown
throw [ScoopException]::new("Decompress error|-Unzip failed: $_") # TerminatingError thrown
}
} else {
# Use Expand-Archive to unzip in PowerShell 5+
Expand Down Expand Up @@ -449,11 +450,11 @@ function Expand-DarkArchive {
try {
$status = Invoke-ExternalCommand (Get-HelperPath -Helper 'Dark') $argList -LogPath $logPath
} catch [System.Management.Automation.ParameterBindingException] {
throw [ScoopException] '''dark'' is not installed or cannot be used' # TerminatingError thrown
throw [ScoopException]::new('''dark'' is not installed or cannot be used') # TerminatingError thrown
}

if (!$status) {
throw [ScoopException] (_decompressErrorPrompt $Path $logPath) # TerminatingError thrown
throw [ScoopException]::new((_decompressErrorPrompt $Path $logPath)) # TerminatingError thrown
}
if (Test-Path $logPath) { Remove-Item $logPath -Force }

Expand Down Expand Up @@ -519,7 +520,7 @@ function Expand-ZstdArchive {

$status = Invoke-ExternalCommand -Path $zstdPath -ArgumentList $_arg -LogPath $_log
if (!$status) {
throw [ScoopException] (_decompressErrorPrompt $_path $_log) # TerminatingError thrown
throw [ScoopException]::new((_decompressErrorPrompt $_path $_log)) # TerminatingError thrown
}

Remove-Item -Path $_log -ErrorAction 'SilentlyContinue' -Force
Expand Down
Loading

0 comments on commit 6154d76

Please sign in to comment.