diff options
-rw-r--r-- | src/luarocks/admin/cache.lua | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/luarocks/admin/cache.lua b/src/luarocks/admin/cache.lua index 0daa0fc0..16a4f5c8 100644 --- a/src/luarocks/admin/cache.lua +++ b/src/luarocks/admin/cache.lua | |||
@@ -47,30 +47,36 @@ function cache.split_server_url(server, url, user, password) | |||
47 | return local_cache, protocol, server_path, user, password | 47 | return local_cache, protocol, server_path, user, password |
48 | end | 48 | end |
49 | 49 | ||
50 | function cache.refresh_local_cache(server, url, user, password) | 50 | local function download_cache(protocol, server_path, user, password) |
51 | local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, user, password) | ||
52 | local ok, err = fs.make_dir(local_cache) | ||
53 | if not ok then | ||
54 | return nil, "Failed creating local cache dir: "..err | ||
55 | end | ||
56 | fs.change_dir(local_cache) | ||
57 | if not ok then return nil, err end | ||
58 | util.printout("Refreshing cache "..local_cache.."...") | ||
59 | |||
60 | -- TODO abstract away explicit 'wget' call | 51 | -- TODO abstract away explicit 'wget' call |
61 | local ok = false | ||
62 | if protocol == "rsync" then | 52 | if protocol == "rsync" then |
63 | local srv, path = server_path:match("([^/]+)(/.+)") | 53 | local srv, path = server_path:match("([^/]+)(/.+)") |
64 | ok = fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/") | 54 | return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") |
65 | else | 55 | else |
66 | local login_info = "" | 56 | local login_info = "" |
67 | if user then login_info = " --user="..user end | 57 | if user then login_info = " --user="..user end |
68 | if password then login_info = login_info .. " --password="..password end | 58 | if password then login_info = login_info .. " --password="..password end |
69 | ok = fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) | 59 | return fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) |
70 | end | 60 | end |
61 | end | ||
62 | |||
63 | function cache.refresh_local_cache(server, url, given_user, given_password) | ||
64 | local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, given_user, given_password) | ||
65 | |||
66 | local ok, err = fs.make_dir(local_cache) | ||
67 | if not ok then | ||
68 | return nil, "Failed creating local cache dir: "..err | ||
69 | end | ||
70 | |||
71 | fs.change_dir(local_cache) | ||
72 | |||
73 | util.printout("Refreshing cache "..local_cache.."...") | ||
74 | |||
75 | ok = download_cache(protocol, server_path, user, password) | ||
71 | if not ok then | 76 | if not ok then |
72 | return nil, "Failed downloading cache." | 77 | return nil, "Failed downloading cache." |
73 | end | 78 | end |
79 | |||
74 | return local_cache, protocol, server_path, user, password | 80 | return local_cache, protocol, server_path, user, password |
75 | end | 81 | end |
76 | 82 | ||