From f3f559c460406689dab2375310fb1026e2be58bd Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Wed, 21 Mar 2018 17:09:11 +0100 Subject: [PATCH] Improve is_scoop_outdated() and add last_scoop_update() --- lib/core.ps1 | 22 +++++++++++++++------- libexec/scoop-update.ps1 | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 78899e9d0d..576307fda0 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -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) { diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index ae73928555..8c713a33ad 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -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')