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
Prev Previous commit
feat: Add Test-ScoopCoreOnHold() to check status
Co-authored-by: Richard Kuhnt <r15ch13+git@gmail.com>
  • Loading branch information
niheaven and r15ch13 committed Aug 12, 2022
commit 05c2a94592dcdbdd25267ab47bc61a6b271e77d7
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
22 changes: 5 additions & 17 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +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." }

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

# 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