From 890c6698f94cf0d4a69cd5e85fdc5ff4bcb79414 Mon Sep 17 00:00:00 2001 From: hisham Date: Tue, 13 Oct 2009 18:45:01 +0000 Subject: Support uploads via sftp (needed for luarocks.org repositories...) git-svn-id: http://luarocks.org/svn/luarocks/trunk@96 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/add.lua | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index ecfdac60..f9d20782 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -13,26 +13,47 @@ local fs = require("luarocks.fs") local cache = require("luarocks.cache") help_summary = "Add a rock or rockspec to a rocks server." -help_arguments = "[--to=] {|]}" +help_arguments = "[--to=] [--no-refresh] {|]}" help = [[ Argument may be a local rockspec or rock file. The flag --to indicates which server to use. If not given, the default server set in the upload_server variable from the configuration file is used instead. +The flag --no-refresh indicates the local cache should not be refreshed +prior to generation of the updated manifest. ]] -local function add_file_to_server(refresh, rockfile, server) +local function add_file_to_server(refresh, rockfile, server, upload_server) + assert(type(refresh) == "boolean" or not refresh) + assert(type(rockfile) == "string") + assert(type(server) == "string") + assert(type(upload_server) == "table" or not upload_server) + if not fs.exists(rockfile) then return nil, "Could not find "..rockfile end + + local download_url = server + local login_url = nil + if upload_server then + if 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 + end local rockfile = fs.absolute_name(rockfile) local local_cache, protocol, server_path, user, password if refresh then - local_cache, protocol, server_path, user, password = cache.refresh_local_cache(server, cfg.upload_user, cfg.upload_password) + local_cache, protocol, server_path, user, password = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) else - local_cache, protocol, server_path, user, password = cache.split_server_url(server, cfg.upload_user, cfg.upload_password) + local_cache, protocol, server_path, user, password = cache.split_server_url(download_url, cfg.upload_user, cfg.upload_password) + end + if not login_url then + login_url = protocol.."://"..server_path end fs.change_dir(local_cache) print("Copying file "..rockfile.." to "..local_cache.."...") @@ -46,12 +67,15 @@ local function add_file_to_server(refresh, rockfile, server) local login_info = "" if user then login_info = " -u "..user end if password then login_info = login_info..":"..password end - if not server_path:match("/$") then - server_path = server_path .. "/" + if not login_url:match("/$") then + login_url = login_url .. "/" end -- TODO abstract away explicit 'curl' call - fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) + + print ("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) + + fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) return true end @@ -69,6 +93,6 @@ function run(...) if cfg.upload_aliases then server = cfg.upload_aliases[server] or server end - return add_file_to_server(not flags["no-refresh"], file, server) + return add_file_to_server(not flags["no-refresh"], file, server, cfg.upload_servers and cfg.upload_servers[server]) end -- cgit v1.2.3-55-g6feb