From ea3d8703b4377ed17c108c6feb5f5e0d4d6ca515 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 22 Jul 2014 01:48:08 +0200 Subject: [PATCH] autoupdater: all fallback for situations with no valid time available --- admin/autoupdater/files/usr/sbin/autoupdater | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/admin/autoupdater/files/usr/sbin/autoupdater b/admin/autoupdater/files/usr/sbin/autoupdater index 34607d6..a3aa006 100755 --- a/admin/autoupdater/files/usr/sbin/autoupdater +++ b/admin/autoupdater/files/usr/sbin/autoupdater @@ -171,7 +171,19 @@ local function get_probability(date, priority) local diff = os.difftime(os.time(), date) if diff < 0 then - return 0 + -- When the difference is negative, there are two possibilities: The manifest contains a wrong date, or our own clock is wrong. + -- As there isn't anything useful to do for an incorrect manifest, we'll assume the latter case and update anyways as we + -- can't do anything better + io.stderr:write('Warning: clock seems to be incorrect.\n') + + if tonumber(fs.readfile('/proc/uptime'):match('^([^ ]+) ')) < 600 then + -- If the uptime is very low, it's possible we just didn't get the time over NTP yet, so we'll just wait until the next time the updater runs + return 0 + else + -- Will give 1 when priority == 0, and lower probabilities the higher the priority value is + -- (similar to the old static probability system) + return 0.9^priority + end elseif diff >= seconds then return 1 elseif oneshot then