aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2019-06-26 14:52:32 +1000
committeronefang2019-06-26 14:52:32 +1000
commit5e8a68623c0241e3a6bdfefd35efdc8f4b16ed5f (patch)
tree32bd932454d02aebf59019b3b60cd58839bdff49
parentVarious changes to the download function. (diff)
downloadapt-panopticon-5e8a68623c0241e3a6bdfefd35efdc8f4b16ed5f.zip
apt-panopticon-5e8a68623c0241e3a6bdfefd35efdc8f4b16ed5f.tar.gz
apt-panopticon-5e8a68623c0241e3a6bdfefd35efdc8f4b16ed5f.tar.bz2
apt-panopticon-5e8a68623c0241e3a6bdfefd35efdc8f4b16ed5f.tar.xz
Retry some of the HTTTP header downloads on certain errors, and report others.
Diffstat (limited to '')
-rwxr-xr-xmirror-checker.lua27
1 files changed, 23 insertions, 4 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua
index 9f70bcd..8b80e3f 100755
--- a/mirror-checker.lua
+++ b/mirror-checker.lua
@@ -173,23 +173,42 @@ local nlst = function (u)
173 return r and table.concat(t), e 173 return r and table.concat(t), e
174end 174end
175 175
176checkURL = function (host, URL, r) 176checkURL = function (host, URL, r, retry)
177 if nil == r then r = 0 end 177 if nil == r then r = 0 end
178 if nil == retry then retry = 0 end
178 local check = "Checking file" 179 local check = "Checking file"
179 if 0 < r then 180 if 0 < r then
180 check = "Redirecting to" 181 check = "Redirecting to"
181-- checkIP(host) 182-- checkHost(host, host)
183 end
184 if 0 < retry then
185 check = "Retry " .. retry .. " " .. check
182 end 186 end
183 if 10 < r then 187 if 10 < r then
184 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL) 188 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL)
185 return 189 return
186 end 190 end
191 if 10 < retry then
192 E("too many retries! " .. check .. " " .. host .. " -> " .. URL)
193 return
194 end
187 local PU = url.parse(URL, defaultURL) 195 local PU = url.parse(URL, defaultURL)
188 D(" " .. PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL) 196 D(" " .. PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL)
189 if not testing(PU.scheme) then D("not testing " .. PU.scheme .. " " .. host .. " -> " .. URL); return end 197 if not testing(PU.scheme) then D("not testing " .. PU.scheme .. " " .. host .. " -> " .. URL); return end
190 local hd = {Host = host} 198 local hd = {Host = host}
191 local p, c, h, s = http.request{method = "HEAD", redirect = false, url = URL, headers = hd} 199 local p, c, h, s = http.request{method = "HEAD", redirect = false, url = URL, headers = hd}
192 if nil == p then E(c .. "! " .. check .. " " .. host .. " -> " .. URL) else 200 if nil == s then s = "" end
201 if nil == p then
202 E(c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL)
203 -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth.
204 -- Might be worthwhile retrying those, some number of times.
205 if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkURL(host, URL, r, retry + 1) end
206 else
207 if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then
208 E(c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL)
209 else
210 I(c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL)
211 end
193 l = h.location 212 l = h.location
194 if nil ~= l then 213 if nil ~= l then
195 local pu = url.parse(l, defaultURL) 214 local pu = url.parse(l, defaultURL)
@@ -203,7 +222,7 @@ checkURL = function (host, URL, r)
203 if testing("Protocol") and pu.scheme ~= PU.scheme then 222 if testing("Protocol") and pu.scheme ~= PU.scheme then
204 W("protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) 223 W("protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l)
205 end 224 end
206 checkURL(pu.host, l, r + 1) 225 checkURL(pu.host, l, r + 1, retry)
207 end 226 end
208 end 227 end
209 end 228 end