aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-08-30 16:27:45 -0300
committerHisham Muhammad <hisham@gobolinux.org>2010-08-30 16:27:45 -0300
commit05e12e918bbd3e2a58a42bf7e5e340ea90667f2e (patch)
tree82d8f2d1e50400e68f2d33a903d261ee89a49606 /src
parent5092954b4f884d3cf1d18dc7e777015bfede3337 (diff)
downloadluarocks-05e12e918bbd3e2a58a42bf7e5e340ea90667f2e.tar.gz
luarocks-05e12e918bbd3e2a58a42bf7e5e340ea90667f2e.tar.bz2
luarocks-05e12e918bbd3e2a58a42bf7e5e340ea90667f2e.zip
Support rsync in "luarocks-admin add"
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/add.lua8
-rw-r--r--src/luarocks/cache.lua25
2 files changed, 20 insertions, 13 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index 5f2ae26c..375861ab 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -32,9 +32,11 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
32 local download_url = server 32 local download_url = server
33 local login_url = nil 33 local login_url = nil
34 if upload_server then 34 if upload_server then
35 if upload_server.http then download_url = "http://"..upload_server.http 35 if upload_server.rsync then download_url = "rsync://"..upload_server.rsync
36 elseif upload_server.http then download_url = "http://"..upload_server.http
36 elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp 37 elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp
37 end 38 end
39
38 if upload_server.ftp then login_url = "ftp://"..upload_server.ftp 40 if upload_server.ftp then login_url = "ftp://"..upload_server.ftp
39 elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp 41 elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp
40 end 42 end
@@ -44,9 +46,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
44 46
45 local local_cache, protocol, server_path, user, password 47 local local_cache, protocol, server_path, user, password
46 if refresh then 48 if refresh then
47 local_cache, protocol, server_path, user, password = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) 49 local_cache, protocol, server_path, user, password = cache.refresh_local_cache(server, download_url, cfg.upload_user, cfg.upload_password)
48 else 50 else
49 local_cache, protocol, server_path, user, password = cache.split_server_url(download_url, cfg.upload_user, cfg.upload_password) 51 local_cache, protocol, server_path, user, password = cache.split_server_url(server, download_url, cfg.upload_user, cfg.upload_password)
50 end 52 end
51 if not local_cache then 53 if not local_cache then
52 return nil, protocol 54 return nil, protocol
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua
index 8ee88df9..77c07d8b 100644
--- a/src/luarocks/cache.lua
+++ b/src/luarocks/cache.lua
@@ -7,8 +7,8 @@ local fs = require("luarocks.fs")
7local cfg = require("luarocks.cfg") 7local cfg = require("luarocks.cfg")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9 9
10function split_server_url(server, user, password) 10function split_server_url(server, url, user, password)
11 local protocol, server_path = dir.split_url(server) 11 local protocol, server_path = dir.split_url(url)
12 if server_path:match("@") then 12 if server_path:match("@") then
13 local credentials 13 local credentials
14 credentials, server_path = server_path:match("([^@]*)@(.*)") 14 credentials, server_path = server_path:match("([^@]*)@(.*)")
@@ -20,13 +20,13 @@ function split_server_url(server, user, password)
20 end 20 end
21 local local_cache 21 local local_cache
22 if cfg.local_cache then 22 if cfg.local_cache then
23 local_cache = cfg.local_cache .. "/" .. server_path 23 local_cache = cfg.local_cache .. "/" .. server
24 end 24 end
25 return local_cache, protocol, server_path, user, password 25 return local_cache, protocol, server_path, user, password
26end 26end
27 27
28function refresh_local_cache(server, user, password) 28function refresh_local_cache(server, url, user, password)
29 local local_cache, protocol, server_path, user, password = split_server_url(server, user, password) 29 local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password)
30 30
31 fs.make_dir(cfg.local_cache) 31 fs.make_dir(cfg.local_cache)
32 32
@@ -42,12 +42,17 @@ function refresh_local_cache(server, user, password)
42 fs.change_dir(local_cache) 42 fs.change_dir(local_cache)
43 print("Refreshing cache "..local_cache.."...") 43 print("Refreshing cache "..local_cache.."...")
44 44
45 local login_info = ""
46 if user then login_info = " --user="..user end
47 if password then login_info = login_info .. " --password="..password end
48
49 -- TODO abstract away explicit 'wget' call 45 -- TODO abstract away explicit 'wget' call
50 local ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) 46 local ok = false
47 if protocol == "rsync" then
48 local srv, path = server_path:match("([^/]+)(/.+)")
49 ok = fs.execute("rsync -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/")
50 else
51 local login_info = ""
52 if user then login_info = " --user="..user end
53 if password then login_info = login_info .. " --password="..password end
54 ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info)
55 end
51 if not ok then 56 if not ok then
52 return nil, "Failed downloading cache." 57 return nil, "Failed downloading cache."
53 end 58 end