From 05e12e918bbd3e2a58a42bf7e5e340ea90667f2e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 30 Aug 2010 16:27:45 -0300 Subject: Support rsync in "luarocks-admin add" --- src/luarocks/add.lua | 8 +++++--- src/luarocks/cache.lua | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src') 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) local download_url = server local login_url = nil if upload_server then - if upload_server.http then download_url = "http://"..upload_server.http + if upload_server.rsync then download_url = "rsync://"..upload_server.rsync + elseif upload_server.http then download_url = "http://"..upload_server.http elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp end + if upload_server.ftp then login_url = "ftp://"..upload_server.ftp elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp end @@ -44,9 +46,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) local local_cache, protocol, server_path, user, password if refresh then - local_cache, protocol, server_path, user, password = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) + local_cache, protocol, server_path, user, password = cache.refresh_local_cache(server, download_url, cfg.upload_user, cfg.upload_password) else - local_cache, protocol, server_path, user, password = cache.split_server_url(download_url, cfg.upload_user, cfg.upload_password) + local_cache, protocol, server_path, user, password = cache.split_server_url(server, download_url, cfg.upload_user, cfg.upload_password) end if not local_cache then 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") local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") -function split_server_url(server, user, password) - local protocol, server_path = dir.split_url(server) +function split_server_url(server, url, user, password) + local protocol, server_path = dir.split_url(url) if server_path:match("@") then local credentials credentials, server_path = server_path:match("([^@]*)@(.*)") @@ -20,13 +20,13 @@ function split_server_url(server, user, password) end local local_cache if cfg.local_cache then - local_cache = cfg.local_cache .. "/" .. server_path + local_cache = cfg.local_cache .. "/" .. server end return local_cache, protocol, server_path, user, password end -function refresh_local_cache(server, user, password) - local local_cache, protocol, server_path, user, password = split_server_url(server, user, password) +function refresh_local_cache(server, url, user, password) + local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password) fs.make_dir(cfg.local_cache) @@ -42,12 +42,17 @@ function refresh_local_cache(server, user, password) fs.change_dir(local_cache) print("Refreshing cache "..local_cache.."...") - local login_info = "" - if user then login_info = " --user="..user end - if password then login_info = login_info .. " --password="..password end - -- TODO abstract away explicit 'wget' call - local ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) + local ok = false + if protocol == "rsync" then + local srv, path = server_path:match("([^/]+)(/.+)") + ok = fs.execute("rsync -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/") + else + local login_info = "" + if user then login_info = " --user="..user end + if password then login_info = login_info .. " --password="..password end + ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) + end if not ok then return nil, "Failed downloading cache." end -- cgit v1.2.3-55-g6feb