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

refactor: Complete abort deprecation 🎉 #53

Merged
merged 25 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion lib/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Set-TerminatingError {
#>
param([Alias('Message')] [String] $Title, [String] $ID = 'Scoop')

if ($PSCmdlet) {
if ($PSCmdlet -and $IsWindows) {
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
([ScoopException]::new($Title)),
Expand Down Expand Up @@ -314,6 +314,7 @@ function New-IssuePrompt {
#>
param([String] $Application, [String] $Bucket, [String] $Title, [String[]] $Body)

$Bucket = $Bucket.Trim()
$app, $manifest, $Bucket, $url = Find-Manifest $Application $Bucket
$url = known_bucket_repo $Bucket
$bucketPath = Join-Path $SCOOP_BUCKETS_DIRECTORY $bucket
Expand Down
5 changes: 1 addition & 4 deletions lib/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,12 @@ function Update-App {
$ok, $err = check_hash $source $manifest_hash (show_app $App $bucket)

if (!$ok) {
Write-UserMessage -Message $err -Err

# Remove cached file
if (Test-Path $source) { Remove-Item $source -Force }
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
}
# TODO: Stop-ScoopExecution
abort (new_issue_msg $App $bucket 'hash check failed')
Set-TerminatingError -Title "Hash check failed|-$err"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u

try {
dl_with_cache $app $version $url $null $null $true
} catch [system.net.webexception] {
Write-UserMessage -Message $_, "URL $url is not valid" -Color DarkRed
} catch {
Write-UserMessage -Message "URL $url is not valid" -Color DarkRed
return $null
}
$file = cache_path $app $version $url
Expand Down
3 changes: 3 additions & 0 deletions lib/commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function Invoke-ScoopCommand {

#region Deprecated
function exec($cmd, $arguments) {
# Show-DeprecatedWarning $MyInvocation 'Invoke-ScoopCommand'
# Invoke-ScoopCommand $cmd $arguments

$cmd_path = command_path $cmd

& $cmd_path @arguments
Expand Down
45 changes: 24 additions & 21 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ function app_status($app, $global) {
$status.hold = ($install_info.hold -eq $true)

$manifest = manifest $app $install_info.bucket $install_info.url
$status.bucket = $install_info.bucket
$status.removed = (!$manifest)
if ($manifest.version) {
$status.latest_version = $manifest.version
Expand All @@ -337,16 +338,16 @@ function app_status($app, $global) {
}

$status.missing_deps = @()
# TODO: Eliminate
. (Join-Path $PSScriptRoot 'depends.ps1')
$deps = @(runtime_deps $manifest) | Where-Object {
$app, $bucket, $null = parse_app $_
return !(installed $app)
}

if ($deps) {
$status.missing_deps += , $deps
}
if ($deps) { $status.missing_deps += , $deps }

return $status
return $status
}

function appname_from_url($url) { return (Split-Path $url -Leaf) -replace '\.json$' }
Expand Down Expand Up @@ -578,7 +579,7 @@ function warn_on_overwrite($shim_ps1, $path) {
if ($shim_app -eq $path_app) { return }

$filename = [System.IO.Path]::GetFileName($path)
warn "Overwriting shim to $filename installed from $shim_app"
Write-UserMessage -Message "Overwriting shim to $filename installed from $shim_app" -Warning
}

function shim($path, $global, $name, $arg) {
Expand Down Expand Up @@ -619,6 +620,7 @@ function shim($path, $global, $name, $arg) {

if ($path -match '\.(exe|com)$') {
# for programs with no awareness of any shell
# TODO: Use relative path from this file
versiondir 'scoop' 'current' | Join-Path -ChildPath 'supporting\shimexe\bin\shim.exe' | Copy-Item -Destination "$shim.exe" -Force
$result = @("path = $resolved_path")
if ($arg) { $result += "args = $arg" }
Expand All @@ -641,11 +643,11 @@ set invalid=`"='
if !args! == !invalid! ( set args= )
powershell -noprofile -ex unrestricted `"& '$resolved_path' $arg %args%;exit `$LASTEXITCODE`"" | Out-File "$shim.cmd" -Encoding Ascii

"#!/bin/sh`npowershell.exe -noprofile -ex unrestricted `"& '$resolved_path'`" $arg `"$@`"" | Out-File $shim -Encoding Ascii
} elseif ($path -match '\.jar$') {
"@java -jar `"$resolved_path`" $arg %*" | Out-File "$shim.cmd" -Encoding Ascii
"#!/bin/sh`njava -jar `"$resolved_path`" $arg `"$@`"" | Out-File $shim -Encoding Ascii
}
"#!/bin/sh`npowershell.exe -noprofile -ex unrestricted `"& '$resolved_path'`" $arg `"$@`"" | Out-File $shim -Encoding Ascii
} elseif ($path -match '\.jar$') {
"@java -jar `"$resolved_path`" $arg %*" | Out-File "$shim.cmd" -Encoding Ascii
"#!/bin/sh`njava -jar `"$resolved_path`" $arg `"$@`"" | Out-File $shim -Encoding Ascii
}
}

function search_in_path($target) {
Expand Down Expand Up @@ -690,9 +692,10 @@ function Confirm-InstallationStatus {
$Installed = @()
$Apps | Select-Object -Unique | Where-Object { $_.Name -ne 'scoop' } | ForEach-Object {
$App, $null, $null = parse_app $_
$buc = (app_status $App $Global).bucket
if ($Global) {
if (installed $App $true) {
$Installed += , @($App, $true)
$Installed += , @($App, $true, $buc)
} elseif (installed $App $false) {
Write-UserMessage -Message "'$App' isn't installed globally, but it is installed for your account." -Err
Write-UserMessage -Message "Try again without the --global (or -g) flag instead." -Warning
Expand All @@ -701,7 +704,7 @@ function Confirm-InstallationStatus {
}
} else {
if (installed $App $false) {
$Installed += , @($App, $false)
$Installed += , @($App, $false, $buc)
} elseif (installed $App $true) {
Write-UserMessage -Message "'$App' isn't installed for your account, but it is installed globally." -Err
Write-UserMessage -Message "Try again with the --global (or -g) flag instead." -Warning
Expand All @@ -711,7 +714,7 @@ function Confirm-InstallationStatus {
}
}

return , $Installed
return , $Installed
}

function strip_path($orig_path, $dir) {
Expand Down Expand Up @@ -764,21 +767,16 @@ function wraptext($text, $width) {
elseif ($line.length + $_.length + 1 -le $width) { $line += " $_" }
else { $lines += , $line; $line = $_ }
}
$lines += , $line
}
$lines += , $line
}

$lines -join "`n"
$lines -join "`n"
}

function pluralize($count, $singular, $plural) {
if ($count -eq 1) { $singular } else { $plural }
}

function reset_aliases() {
Show-DeprecatedWarning $MyInvocation 'Reset-Alias'
Reset-Alias
}

# convert list of apps to list of ($app, $global) tuples
function applist($apps, $global) {
if (!$apps) { return @() }
Expand Down Expand Up @@ -913,6 +911,11 @@ function handle_special_urls($url) {
}

#region Deprecated
function reset_aliases() {
Show-DeprecatedWarning $MyInvocation 'Reset-Alias'
Reset-Alias
}

function file_path($app, $file) {
Show-DeprecatedWarning $MyInvocation 'Get-AppFilePath'
return Get-AppFilePath -App $app -File $file
Expand Down
2 changes: 1 addition & 1 deletion lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function Expand-ZipArchive {
Expand-7zipArchive $Path $DestinationPath -Removal:$Removal
return
} else {
Set-TerminatingError -Title "Ignore|-Unzip failed: Windows cannot handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again."
Set-TerminatingError -Title "Ignore|-Unzip failed: Windows cannot handle long paths in this zip file.`nRun 'scoop install 7zip' and try again."
}
} catch [System.IO.IOException] {
if (Test-HelperInstalled -Helper 7zip) {
Expand Down
25 changes: 18 additions & 7 deletions lib/depends.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
function install_order($apps, $arch) {
$res = @()
foreach ($app in $apps) {
foreach ($dep in deps $app $arch) {
$deps = @()
try {
$deps = deps $app $arch
} catch {
Write-UserMessage -Message $_.Exception.Message -Err
continue
}

foreach ($dep in $deps) {
if ($res -notcontains $dep) { $res += $dep }
}
if ($res -notcontains $app) { $res += $app }
Expand All @@ -21,30 +29,33 @@ function deps($app, $arch) {
$resolved = New-Object System.Collections.ArrayList
dep_resolve $app $arch $resolved @()

if ($resolved.count -eq 1) { return @() } # No dependencies
if ($resolved.Count -eq 1) { return @() } # No dependencies

return $resolved[0..($resolved.count - 2)]
return $resolved[0..($resolved.Count - 2)]
}

function dep_resolve($app, $arch, $resolved, $unresolved) {
#[out]$resolved
#[out]$unresolved

$app, $bucket, $null = parse_app $app
$unresolved += $app
$null, $manifest, $null, $null = Find-Manifest $app $bucket

if (!$manifest) {
if (((Get-LocalBucket) -notcontains $bucket) -and $bucket) {
if ($bucket -and ((Get-LocalBucket) -notcontains $bucket)) {
Write-UserMessage -Message "Bucket '$bucket' not installed. Add it with 'scoop bucket add $bucket' or 'scoop bucket add $bucket <repo>'." -Warning
}
# TODO: Stop-ScoopExecution: Throw
abort "Couldn't find manifest for '$app'$(if(!$bucket) { '.' } else { " from '$bucket' bucket." })"

Set-TerminatingError -Title "Ignore|-Could not find manifest for '$app'$(if(!$bucket) { '.' } else { " from '$bucket' bucket." })"
}

$deps = @(install_deps $manifest $arch) + @(runtime_deps $manifest) | Select-Object -Unique

foreach ($dep in $deps) {
if ($resolved -notcontains $dep) {
if ($unresolved -contains $dep) {
abort "Circular dependency detected: '$app' -> '$dep'."
Set-TerminatingError -Title "Invalid manifest|-Circular dependency detected: '$app' -> '$dep'."
}
dep_resolve $dep $arch $resolved $unresolved
}
Expand Down
Loading