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

feat(scoop-(un)hold): Support scoop (un)hold scoop #5089

Merged
merged 34 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
66296dc
feat(scoop-config): Add new configuration of `SCOOP_HOLD`
yi-Xu-0100 Aug 6, 2022
d740651
perf(scoop-update): Separate `update_bucket` from `update_scoop`
yi-Xu-0100 Aug 7, 2022
2e54195
perf(scoop-(un)hold): remove big overarching if-statement
yi-Xu-0100 Aug 7, 2022
0cb48c2
perf(scoop-config): use `SCOOP_HOLD_DAYS` instead of `SCOOP_HOLD`
yi-Xu-0100 Aug 8, 2022
3db0991
perf(scoop-config): Update forward Compatible code
yi-Xu-0100 Aug 8, 2022
5359483
Update libexec/scoop-config.ps1
yi-Xu-0100 Aug 8, 2022
6b50203
Update libexec/scoop-hold.ps1
yi-Xu-0100 Aug 8, 2022
68ce6aa
Update libexec/scoop-unhold.ps1
yi-Xu-0100 Aug 8, 2022
5f51ba8
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 8, 2022
7f63df2
perf(scoop-update): Update last_scoop_update
yi-Xu-0100 Aug 8, 2022
5b2b622
docs(changelog): update changelog to add feature
yi-Xu-0100 Aug 8, 2022
99e8af4
fix(changelog): fix changelog typo
yi-Xu-0100 Aug 8, 2022
9e6090a
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 8, 2022
01cb22c
Update libexec/scoop-config.ps1
yi-Xu-0100 Aug 8, 2022
36c39dd
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 8, 2022
9d434ea
refactor: Use `lastUpdate` instead of `lastupdate`
yi-Xu-0100 Aug 8, 2022
b7b2d1e
fix(install): make config lastUpdate silent
yi-Xu-0100 Aug 8, 2022
23a8c45
refactor(scoop-update): Remove `SCOOP_HOLD`
yi-Xu-0100 Aug 8, 2022
6fea71b
fix: update changelog
yi-Xu-0100 Aug 8, 2022
d271913
Update lib/core.ps1
yi-Xu-0100 Aug 9, 2022
5b69df4
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
d555b05
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
76eb3af
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
d0968cc
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
d3cae39
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
d9a7403
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
8bf4193
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
c500a5b
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
ab5d102
Update libexec/scoop-update.ps1
yi-Xu-0100 Aug 9, 2022
ce151cb
perf(scoop-update): Handle the judgment in try-catch
yi-Xu-0100 Aug 9, 2022
c28e207
fix(scoop-update): Remove 'update_until' when update scoop itself
yi-Xu-0100 Aug 9, 2022
4a2498d
Update lib/core.ps1
yi-Xu-0100 Aug 9, 2022
7b3f87b
Merge branch 'develop' into develop
yi-Xu-0100 Aug 10, 2022
2fa93d1
docs(CHANGELOG): Update changelog
yi-Xu-0100 Aug 10, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- **install:** Show bucket name while installing an app ([#5075](https://github.com/ScoopInstaller/Scoop/issues/5075))
- **scoop-status:** Add flag to disable remote checking ([#5073](https://github.com/ScoopInstaller/Scoop/issues/5073))
- **scoop-update:** Add support for `pre_uninstall` and `post_uninstall` ([#5085](https://github.com/ScoopInstaller/Scoop/issues/5085))
- **scoop-(un)hold:** Support `scoop (un)hold scoop` ([#5089](https://github.com/ScoopInstaller/Scoop/issues/5089))

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion bin/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Remove-Item "$dir\_tmp", $zipfile -Recurse -Force

ensure_robocopy_in_path

scoop config lastupdate ([System.DateTime]::Now.ToString('o'))
set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null
success 'Scoop was installed successfully!'

Write-Output "Type 'scoop help' for instructions."
Expand Down
25 changes: 6 additions & 19 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -996,29 +996,16 @@ function show_app($app, $bucket, $version) {
return $app
}

function last_scoop_update() {
# PowerShell 6 returns an DateTime Object
$last_update = (get_config lastupdate)

if ($null -ne $last_update -and $last_update.GetType() -eq [System.String]) {
try {
$last_update = [System.DateTime]::Parse($last_update)
} catch {
$last_update = $null
}
}
return $last_update
}

function is_scoop_outdated() {
$last_update = $(last_scoop_update)
$now = [System.DateTime]::Now
yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
if($null -eq $last_update) {
set_config lastupdate $now.ToString('o')
# enforce an update for the first time
try{
yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
$expireHour = (New-TimeSpan (get_config lastUpdate) $now).TotalHours
return ($expireHour -ge 3)
} catch {
# If not System.DateTime
set_config lastUpdate ($now.ToString('o')) | Out-Null
return $true
}
return $last_update.AddHours(3) -lt $now.ToLocalTime()
}

function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
Expand Down
6 changes: 6 additions & 0 deletions libexec/scoop-hold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ if ($global -and !(is_admin)) {
$apps | ForEach-Object {
$app = $_

if ($app -eq 'scoop') {
$update_until = [System.DateTime]::Now.AddDays(1)
set_config 'update_until' $update_until.ToString('o') | Out-Null
success "$app is now held and might not be updated until $($update_until.ToLocalTime())."
return
}
if (!(installed $app $global)) {
if ($global) {
error "'$app' is not installed globally."
Expand Down
5 changes: 5 additions & 0 deletions libexec/scoop-unhold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ if ($global -and !(is_admin)) {
$apps | ForEach-Object {
$app = $_

if ($app -eq 'scoop') {
set_config 'update_until' $null | Out-Null
success "$app is no longer held and can be updated again."
return
}
if (!(installed $app $global)) {
if ($global) {
error "'$app' is not installed globally."
Expand Down
42 changes: 31 additions & 11 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ if(($PSVersionTable.PSVersion.Major) -lt 5) {
Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows"
break
}
$show_update_log = get_config 'show_update_log' $true

yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
function update_scoop() {
function update_scoop($show_update_log) {
# check for git
if(!(Test-CommandAvailable git)) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }
if (!(Test-CommandAvailable git)) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }

try {
$now = [System.DateTime]::Now.ToString('o')
$update_until = [System.DateTime]::Parse((get_config update_until $now))
if ((New-TimeSpan $update_until $now).TotalSeconds -lt 0) {
yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
warn "Skipping self-update until $($update_until.ToLocalTime())..."
warn "If you want to update Scoop itself immediately, use 'scoop unhold scoop; scoop update'."
return
}
} catch {
warn "'update_until' has been set in the wrong format."
warn "If you want to disable Scoop self-update for a moment, use 'scoop hold scoop'."
}

set_config update_until $null | Out-Null

Write-Host "Updating Scoop..."
$last_update = $(last_scoop_update)
if ($null -eq $last_update) {$last_update = [System.DateTime]::Now}
$last_update = $last_update.ToString('s')
$show_update_log = get_config 'show_update_log' $true
$currentdir = fullpath $(versiondir 'scoop' 'current')
if (!(Test-Path "$currentdir\.git")) {
$newdir = "$currentdir\..\new"
Expand Down Expand Up @@ -135,6 +147,11 @@ function update_scoop() {
# }

shim "$currentdir\bin\scoop.ps1" $false
}

function update_bucket($show_update_log) {
# check for git
if (!(Test-CommandAvailable git)) { abort "Scoop uses Git to update main bucket and others. Run 'scoop install git' and try again." }

foreach ($bucket in Get-LocalBucket) {
Write-Host "Updating '$bucket' bucket..."
Expand Down Expand Up @@ -165,9 +182,6 @@ function update_scoop() {
git -C "$bucketLoc" --no-pager log --no-decorate --grep='^(chore)' --invert-grep --format='tformat: * %C(yellow)%h%Creset %<|(72,trunc)%s %C(cyan)%cr%Creset' "$previousCommit..HEAD"
}
}

set_config lastupdate ([System.DateTime]::Now.ToString('o')) | Out-Null
success 'Scoop was updated successfully!'
}

function update($app, $global, $quiet = $false, $independent, $suggested, $use_cache = $true, $check_hash = $true) {
Expand Down Expand Up @@ -304,7 +318,10 @@ if (-not ($apps -or $all)) {
error 'scoop update: --no-cache is invalid when <app> is not specified.'
exit 1
}
update_scoop
update_scoop $show_update_log
update_bucket $show_update_log
set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null
yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
success 'Scoop was updated successfully!'
} else {
if ($global -and !(is_admin)) {
'ERROR: You need admin rights to update global apps.'; exit 1
Expand All @@ -316,7 +333,10 @@ if (-not ($apps -or $all)) {
$apps_param = $apps

if ($updateScoop) {
update_scoop
update_scoop $show_update_log
update_bucket $show_update_log
set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null
yi-Xu-0100 marked this conversation as resolved.
Show resolved Hide resolved
success 'Scoop was updated successfully!'
}

if ($apps_param -eq '*' -or $all) {
Expand Down