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 all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- **scoop-(un)hold:** Support `scoop (un)hold scoop` ([#5089](https://github.com/ScoopInstaller/Scoop/issues/5089))
- **scoop-config:** Allow 'hold_update_until' be set manually ([#5100](https://github.com/ScoopInstaller/Scoop/issues/5100))
- **scoop-update:** Stash uncommitted changes before update ([#5091](https://github.com/ScoopInstaller/Scoop/issues/5091))

## [v0.2.4](https://github.com/ScoopInstaller/Scoop/compare/v0.2.3...v0.2.4) - 2022-08-08
Expand Down
23 changes: 23 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,29 @@ function is_scoop_outdated() {
}
}

function Test-ScoopCoreOnHold() {
$hold_update_until = get_config hold_update_until
if ($null -eq $hold_update_until) {
return $false
}
$parsed_date = New-Object -TypeName DateTime
if ([System.DateTime]::TryParse($hold_update_until, $null, [System.Globalization.DateTimeStyles]::AssumeLocal, [ref]$parsed_date)) {
if ((New-TimeSpan $parsed_date).TotalSeconds -lt 0) {
warn "Skipping self-update of Scoop Core until $($parsed_date.ToLocalTime())..."
warn "If you want to update Scoop Core immediately, use 'scoop unhold scoop; scoop update'."
return $true
} else {
warn 'Self-update of Scoop Core is enabled again!'
}
} else {
error "'hold_update_until' has been set in the wrong format and was removed."
error 'If you want to disable self-update of Scoop Core for a moment,'
error "use 'scoop hold scoop' or 'scoop config hold_update_until <YYYY-MM-DD>/<YYYY/MM/DD>'."
}
set_config hold_update_until $null | Out-Null
return $false
}

function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
$newentity = $entity
if ($null -ne $newentity) {
Expand Down
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
20 changes: 5 additions & 15 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,13 @@ if(($PSVersionTable.PSVersion.Major) -lt 5) {
$show_update_log = get_config 'show_update_log' $true

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
}
} 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'."
# Test if Scoop Core is hold
if(Test-ScoopCoreOnHold) {
return
}

set_config update_until $null | Out-Null
# check for git
if (!(Test-CommandAvailable git)) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }

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