From dbf65dd0c9b57e92579669a40fb9c9e7a8b2af0a Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 25 Dec 2019 23:12:12 +1000 Subject: Proper Updated check. --- apt-panopticon.lua | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 5493683..b7a35fc 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -591,6 +591,19 @@ local getMirrors = function () active = false m[t] = d -- TODO - Should do some input validation on BaseURL, and everything else. + elseif "Rate" == t then + local time, unit = d:match('(%d+) *(%a+)') + time = tonumber(time) + unit = unit:sub(1, 1) + m[t] = time .. ' ' .. unit + if 'm' == unit then + time = time * 60 + elseif 'h' == unit then + time = time * 60 * 60 + else + C('Unknown Rate for mirror ' .. host) + end + m['Updated'] = time else m[t] = d end @@ -600,9 +613,14 @@ local getMirrors = function () end end if APT.testing("DNSRR") then - mirrors[APT.options.roundRobin.value] = { ["Protocols"] = { ["http"] = true; ["https"] = true; }; + mirrors[APT.options.roundRobin.value] = { ["Protocols"] = { ["http"] = true; ["https"] = true; }; ['Updated'] = 300; ["FQDN"] = APT.options.roundRobin.value; ["Active"] = 'yes'; ["BaseURL"] = APT.options.roundRobin.value; } end + local file, e = io.open("results/mirrors.lua", "w+") + if nil == file then C("opening mirrors file - " .. e) else + file:write(APT.dumpTable(mirrors, "", "mirrors") .. "\nreturn mirrors\n") + file:close() + end return mirrors end @@ -754,7 +772,12 @@ end local parseRelease = function(host) local list = {inf = 'Release', parser = parsePackages, out = 'Packages', files = {}, nextf = 'debs'} + local updated = false + local status, now = APT.execute('TZ="GMT" date "+%s"', false) + now = tonumber(now:sub(2, -2)) for i, n in pairs(releases) do + local status, old = APT.execute([[TZ="GMT" date -d "$(grep '^Date:' results_old/pkgmaster.devuan.org/merged/dists/]] .. n .. [[/Release.SORTED | cut -d ' ' -f 2-)" '+%s']], false) + old = tonumber(old:sub(2, -2)) for l, o in pairs(releaseFiles) do if repoExists(i .. o) then postDownload(host, n, o) @@ -784,13 +807,28 @@ local parseRelease = function(host) os.execute('rm -f results/' .. host .. '/merged/dists/' .. n .. '/Release 2>/dev/null; ') else -- TODO - compare to the pkgmaster copy. + if APT.testing('Updated') then + local status, new = APT.execute([[TZ="GMT" date -d "$(grep '^Date:' results/]] .. host .. [[/merged/dists/]] .. n .. [[/Release.SORTED | cut -d ' ' -f 2-)" '+%s']], false) + new = tonumber(new:sub(2, -2)) + local upd = old + APT.mirrors[host].Updated + if old ~= new then + if upd >= now then + W('Release ' .. n .. ' not updated yet, should update @ ' .. os.date('!%F %T', upd), 'http', 'Updated', host) + else + E('Release ' .. n .. ' not updated, should have updated @ ' .. os.date('!%F %T', upd) .. ', but was last updated @ ' .. os.date('!%F %T', new), 'http', 'Updated', host) + end + updated = false + else + updated = true + end + end end -- TODO - if it's not Integrity and not reference, then just do a HEAD check and compare file times? -- TODO - like we do with debs, pick just the smallest Packages.xz that has changed. -- Though we are sorting Release by name, so we can do the diff with the one from results_old, so we'll need to sort by size to. -- pkgmaster still needs to download all the changed Packages.xz files though. - if APT.testing("Integrity") or (APT.options.referenceSite.value == host) then + if updated or APT.testing("Integrity") or (APT.options.referenceSite.value == host) then local dfile, e = io.open(outFile, "r") if nil == dfile then W("opening " .. outFile .. " file - " .. e) else for l in dfile:lines() do @@ -931,6 +969,7 @@ if 0 < #arg then I("Starting tests for " .. arg[1] .. " with these tests - " .. table.concat(APT.options.tests.value, ", ")) if nil ~= arg[2] then I(" Using IP " .. arg[2]); ip = arg[2] end if nil ~= arg[3] then I(" Using file " .. arg[3]); end + APT.mirrors = loadfile("results/mirrors.lua")() APT.results = APT.padResults(APT.results) if APT.origin then -- cgit v1.1