From 7134f592a0a2064fd04f0e169d7801b51504e4c6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 18 Sep 2012 18:19:22 -0300 Subject: Add mirroring support. String-array entries in the array of rocks_servers will be treated as a list of mirrors. --- Makefile | 3 --- src/luarocks/cfg.lua | 5 ++++- src/luarocks/search.lua | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c8d1d972..35a366bd 100644 --- a/Makefile +++ b/Makefile @@ -136,9 +136,6 @@ write_sysconfig: built if [ ! -f "$(DESTDIR)$(CONFIG_FILE)" ] ;\ then \ mkdir -p `dirname "$(DESTDIR)$(CONFIG_FILE)"` ;\ - echo 'rocks_servers = {' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - echo ' [[http://luarocks.org/repositories/rocks]]' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - echo '}' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ echo 'rocks_trees = {' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ if [ ! -n "$(FORCE_CONFIG)" ] ;\ then \ diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index efe5de36..263af063 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -171,7 +171,10 @@ local defaults = { obj_extension = "unknown", rocks_servers = { - "http://www.luarocks.org/repositories/rocks" + { + "http://www.luarocks.org/repositories/rocks", + "http://luarocks.giga.puc-rio.br/" + } }, lua_extension = "lua", diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 5df2bd38..9c53632a 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -194,13 +194,20 @@ function search_repos(query) local results = {} for _, repo in ipairs(cfg.rocks_servers) do - local protocol, pathname = dir.split_url(repo) - if protocol == "file" then - repo = pathname + if type(repo) == "string" then + repo = { repo } end - local ok, err = manifest_search(results, repo, query) - if not ok then - 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 = manifest_search(results, mirror, query) + if ok then + break + else + util.warning("Failed searching manifest: "..err) + end end end return results -- cgit v1.2.3-55-g6feb