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-config): Allow 'hold_update_until' be set manually #5100

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
feat(scoop-config): Allow 'hold_update_until' be manually set
  • Loading branch information
niheaven committed Aug 11, 2022
commit 7def5f722f295b52dd977c983d28eee39a7f48eb
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