From f1b487e17eb1a41f7bfd47102821e8e7c2ab49e7 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 31 Dec 2019 00:22:00 +1000 Subject: Rearrange the status and STATUS checks in HEAD tests. --- apt-panopticon.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 2959fc7..093d3ff 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -284,20 +284,6 @@ checkHEAD = function (host, URL, r, retry, sanity) IP .. ' ' .. '-o /dev/null -D results/"HEADERS_' .. fname .. '" ' .. hdr .. ' -w "#%{http_code} %{ssl_verify_result} %{url_effective}\\n" ' .. PU.scheme .. '://' .. host .. PU.path .. ' >>results/"STATUS_' .. fname .. '"' ):Nice():log():Do().status - os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm -f results/"HEADERS_' .. fname .. '" 2>/dev/null') - if 0 ~= status then - local msg = curlStatus[status] - if nil == msg then msg = "UNKNOWN CURL STATUS CODE!" end - if (28 == status) or (7 == status) then - T(spcd .. spcd .. "TIMEOUT " .. timeouts + 1 .. ", retry " .. retry + 1 .. ' ' .. APT.lnk(URL), PU.scheme, sanity, host) - timeouts = timeouts + 1 - else - E(spcd .. spcd .. "The curl command return an error code of " .. status .. " - " .. msg .. ' for '.. APT.lnk(URL), PU.scheme, sanity, host) - end - if 60 == status then return end -- Certificate is invalid, don't bother retrying. - checkHEAD(host, URL, r, retry + 1, '' ~= sanity) - return - end local code = "???" local cstr = "" local location = nil @@ -310,15 +296,31 @@ checkHEAD = function (host, URL, r, retry, sanity) T(spcd .. spcd .. "TIMEOUT " .. timeouts + 1 .. ", retry " .. retry + 1 .. ' ' .. APT.lnk(URL), PU.scheme, sanity, host) timeouts = timeouts + 1 checkHEAD(host, URL, r, retry + 1, '' ~= sanity) + os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm -f results/"HEADERS_' .. fname .. '" 2>/dev/null') return end end + os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm -f results/"HEADERS_' .. fname .. '" 2>/dev/null') + if 0 ~= status then + local msg = curlStatus[status] + if nil == msg then msg = "UNKNOWN CURL STATUS CODE!" end + if (28 == status) or (7 == status) then + T(spcd .. spcd .. "TIMEOUT " .. timeouts + 1 .. ", retry " .. retry + 1 .. ' ' .. APT.lnk(URL), PU.scheme, sanity, host) + timeouts = timeouts + 1 + else + E(spcd .. spcd .. "The curl command return an error code of " .. status .. " - " .. msg .. ' for '.. APT.lnk(URL), PU.scheme, sanity, host) + end + if 60 == status then return end -- Certificate is invalid, don't bother retrying. + checkHEAD(host, URL, r, retry + 1, '' ~= sanity) + return + end local rfile, e = io.open("results/STATUS_" .. fname, "r") if nil == rfile then W("opening results/STATUS_" .. fname .. " file - " .. e) else for line in rfile:lines("*l") do if "#" == line:sub(1, 1) then code = line:sub(2, 4) if ("https" == PU.scheme) and ("0" ~= line:sub(6, 6)) then + os.execute('cp results/STATUS_' .. fname .. ' results/STATUS_' .. fname .. '_SAVED') if '' ~= sanity then E(spcd .. spcd .. "The certificate is invalid.", PU.scheme, sanity, host) else @@ -332,7 +334,6 @@ checkHEAD = function (host, URL, r, retry, sanity) location = line:sub(11, -2) end end - os.execute('rm -f results/STATUS_' .. fname .. ' 2>/dev/null') end if ("4" == tostring(code):sub(1, 1)) or ("5" == tostring(code):sub(1, 1)) then E(spcd .. spcd .. code .. " " .. cstr .. ". " .. check .. " " .. APT.lnk(URL), PU.scheme, sanity, host) @@ -1051,7 +1052,6 @@ os.execute('sleep 1') -- Wait for things to start up before checking for them. while 0 < APT.checkExes(downloadLock .. "package-" .. pu.host .. ".log.txt") do os.execute("sleep 10") end os.execute("sleep 5") if not APT.keep then os.execute("rm -fr results/" .. pu.host .. " 2>/dev/null") end - os.execute('rm results/STATUS_' .. pu.host .. '_* 2>/dev/null') end APT.logPost() -- cgit v1.1