Skip to content

Commit

Permalink
feat(scoop-config): Allow 'hold_update_until' be manually set
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Aug 11, 2022
1 parent bd12393 commit 7def5f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 6 additions & 0 deletions libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
# For example, if you want to access a private GitHub repository,
# you need to add the host to this list with 'match' and 'headers' strings.
#
# hold_update_until:
# Disable/Hold Scoop self-updates, until the specified date.
# `scoop hold scoop` will set the value to one day later.
# Should be in the format 'YYYY-MM-DD', 'YYYY/MM/DD' or any other forms that accepted by '[System.DateTime]::Parse()'.
# Ref: https://docs.microsoft.com/dotnet/api/system.datetime.parse?view=netframework-4.5#StringToParse
#
# ARIA2 configuration
# -------------------
#
Expand Down
6 changes: 3 additions & 3 deletions libexec/scoop-hold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ $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())."
$hold_update_until = [System.DateTime]::Now.AddDays(1)
set_config 'hold_update_until' $hold_update_until.ToString('o') | Out-Null
success "$app is now held and might not be updated until $($hold_update_until.ToLocalTime())."
return
}
if (!(installed $app $global)) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-unhold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $apps | ForEach-Object {
$app = $_

if ($app -eq 'scoop') {
set_config 'update_until' $null | Out-Null
set_config 'hold_update_until' $null | Out-Null
success "$app is no longer held and can be updated again."
return
}
Expand Down
24 changes: 13 additions & 11 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,22 @@ 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." }

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) {
warn "Skipping self-update until $($update_until.ToLocalTime())..."
warn "If you want to update Scoop itself immediately, use 'scoop unhold scoop; scoop update'."
return
$hold_update_until = get_config hold_update_until
if ($null -ne $hold_update_until) {
try {
$hold_update_until = [System.DateTime]::Parse($hold_update_until, $null, [System.Globalization.DateTimeStyles]::AssumeLocal)
if ((New-TimeSpan $hold_update_until).TotalSeconds -lt 0) {
warn "Skipping self-update until $($hold_update_until.ToLocalTime())..."
warn "If you want to update Scoop itself immediately, use 'scoop unhold scoop; scoop update'."
return
}
} catch {
warn "'hold_update_until' has been set in the wrong format and would be removed."
warn "If you want to disable Scoop self-update for a moment, use 'scoop hold scoop' or 'scoop config hold_update_until <YYYY-MM-DD>/<YYYY/MM/DD>'."
}
} 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 hold_update_until $null | Out-Null
}

set_config update_until $null | Out-Null

Write-Host "Updating Scoop..."
$currentdir = fullpath $(versiondir 'scoop' 'current')
Expand Down

0 comments on commit 7def5f7

Please sign in to comment.