Skip to content

Commit

Permalink
Improve is_scoop_outdated() and add last_scoop_update()
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed Mar 21, 2018
1 parent 7cc6e96 commit f3f559c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,24 @@ function get_app_with_version([String] $app) {
"version" = if ($version) { $version } else { 'latest' }
}
}

function last_scoop_update() {
$last_update = (scoop config lastupdate)
if(!$last_update) {
$last_update = [System.DateTime]::Now
}
return $last_update.ToLocalTime()
}

function is_scoop_outdated() {
$now = Get-Date
try {
$last_update = (Get-Date $(scoop config lastupdate)).ToLocalTime().AddHours(3)
} catch {
$last_update = $(last_scoop_update)
$now = [System.DateTime]::Now
if($last_update -eq $now) {
scoop config lastupdate $now
# remove 1 minute to force an update for the first time
$last_update = $now.AddMinutes(-1)
# enforce an update for the first time
return $true
}
return $last_update -lt $now.ToLocalTime()
return $last_update.AddHours(3) -lt [System.DateTime]::Now.ToLocalTime()
}

function substitute($entity, [Hashtable] $params) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function update_scoop() {
if(!$git) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }

write-host "Updating Scoop..."
$last_update = (Get-Date (Get-Date $(scoop config lastupdate)).ToLocalTime() -Format s)
$last_update = $(last_scoop_update).ToString('s')
$currentdir = fullpath $(versiondir 'scoop' 'current')
if(!(test-path "$currentdir\.git")) {
$newdir = fullpath $(versiondir 'scoop' 'new')
Expand Down

0 comments on commit f3f559c

Please sign in to comment.