From 11757127cdcd5d15d40f189f4b03e32328063cd9 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 19 Apr 2010 17:58:52 -0300 Subject: Support adding multiple files at once; use scp for copying. Still a hack but works better than curl in most installations. (Backport from svn) --- src/luarocks/add.lua | 54 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index 56021bb4..5f2ae26c 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -13,9 +13,9 @@ local fs = require("luarocks.fs") local cache = require("luarocks.cache") help_summary = "Add a rock or rockspec to a rocks server." -help_arguments = "[--to=] [--no-refresh] {|]}" +help_arguments = "[--to=] [--no-refresh] {|...}" help = [[ -Argument may be a local rockspec or rock file. +Arguments are local files, which may be rockspecs or rocks. 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. @@ -23,16 +23,12 @@ 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, upload_server) +local function add_files_to_server(refresh, rockfiles, server, upload_server) assert(type(refresh) == "boolean" or not refresh) - assert(type(rockfile) == "string") + assert(type(rockfiles) == "table") 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 @@ -43,8 +39,8 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp end end - - local rockfile = fs.absolute_name(rockfile) + + local at = fs.current_dir() local local_cache, protocol, server_path, user, password if refresh then @@ -58,9 +54,25 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) if not login_url then login_url = protocol.."://"..server_path end + + fs.change_dir(at) + + local files = {} + for i, rockfile in ipairs(rockfiles) do + if fs.exists(rockfile) then + print("Copying file "..rockfile.." to "..local_cache.."...") + local absolute = fs.absolute_name(rockfile) + fs.copy(absolute, local_cache) + table.insert(files, dir.base_name(absolute)) + else + print("File "..rockfile.." not found") + end + end + if #files == 0 then + return nil, "No files found" + end + fs.change_dir(local_cache) - print("Copying file "..rockfile.." to "..local_cache.."...") - fs.copy(rockfile, local_cache) print("Updating manifest...") manif.make_manifest(local_cache) @@ -76,16 +88,24 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) -- TODO abstract away explicit 'curl' call - print ("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) + local cmd + if upload_server.sftp then + local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") + cmd = "scp manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 + else + cmd = "curl "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url + end - fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) + print(cmd) + fs.execute(cmd) return true end function run(...) - local flags, file = util.parse_flags(...) - if type(file) ~= "string" then + local files = { util.parse_flags(...) } + local flags = table.remove(files, 1) + if #files < 1 then return nil, "Argument missing, see help." end local server = flags["to"] @@ -93,6 +113,6 @@ function run(...) if not server then return nil, "No server specified with --to and no default configured with upload_server." end - return add_file_to_server(not flags["no-refresh"], file, server, cfg.upload_servers and cfg.upload_servers[server]) + return add_files_to_server(not flags["no-refresh"], files, server, cfg.upload_servers and cfg.upload_servers[server]) end -- cgit v1.2.3-55-g6feb