From e6ebf473e09afed69895e6501580fbc47bf13534 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 8 Feb 2014 18:32:35 -0200 Subject: When a server times out, stop using it and move down the mirrors list. --- src/luarocks/cfg.lua | 1 + src/luarocks/fs/lua.lua | 3 +++ src/luarocks/manif.lua | 8 ++++---- src/luarocks/search.lua | 33 +++++++++++++++++++-------------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 484bfb79..f38ae9a8 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -219,6 +219,7 @@ local defaults = { "http://luarocks.logiceditor.com/rocks", } }, + disabled_servers = {}, lua_extension = "lua", lua_interpreter = site_config.LUA_INTERPRETER or "lua", diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 6aca2b69..a95e7c51 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -602,6 +602,9 @@ local function http_request(url, http, cached) if status == 200 and headers["last-modified"] == timestamp then return true end + if not result then + return nil, status + end end end local result, status, headers, err = request(url, "GET", http) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 3fb3e4e3..b9a65b09 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -129,15 +129,15 @@ function load_manifest(repo_url) end end else - local err + local err, errcode for _, filename in ipairs(filenames) do - pathname, err = fetch_manifest_from(repo_url, filename) - if pathname then + pathname, err, errcode = fetch_manifest_from(repo_url, filename) + if pathname or errcode == "network" then break end end if not pathname then - return nil, err + return nil, err, errcode end end if pathname:match(".*%.zip$") then diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index bd636352..f0659e0f 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -170,9 +170,9 @@ function manifest_search(results, repo, query) assert(type(query) == "table") query_arch_as_table(query) - local manifest, err = manif.load_manifest(repo) + local manifest, err, errcode = manif.load_manifest(repo) if not manifest then - return nil, "Failed loading manifest: "..err + return nil, err, errcode end for name, versions in pairs(manifest.repository) do for version, items in pairs(versions) do @@ -194,19 +194,24 @@ function search_repos(query) local results = {} for _, repo in ipairs(cfg.rocks_servers) do - if type(repo) == "string" then - repo = { repo } - end - for _, mirror in ipairs(repo) do - local protocol, pathname = dir.split_url(mirror) - if protocol == "file" then - mirror = pathname + if not cfg.disabled_servers[repo] then + if type(repo) == "string" then + repo = { repo } end - local ok, err = manifest_search(results, mirror, query) - if ok then - break - else - util.warning("Failed searching manifest: "..err) + for _, mirror in ipairs(repo) do + local protocol, pathname = dir.split_url(mirror) + if protocol == "file" then + mirror = pathname + end + local ok, err, errcode = manifest_search(results, mirror, query) + if errcode == "network" then + cfg.disabled_servers[repo] = true + end + if ok then + break + else + util.warning("Failed searching manifest: "..err) + end end end end -- cgit v1.2.3-55-g6feb