diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/add.lua | 54 |
1 files changed, 37 insertions, 17 deletions
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") | |||
13 | local cache = require("luarocks.cache") | 13 | local cache = require("luarocks.cache") |
14 | 14 | ||
15 | help_summary = "Add a rock or rockspec to a rocks server." | 15 | help_summary = "Add a rock or rockspec to a rocks server." |
16 | help_arguments = "[--to=<server>] [--no-refresh] {<rockspec>|<rock>]}" | 16 | help_arguments = "[--to=<server>] [--no-refresh] {<rockspec>|<rock>...}" |
17 | help = [[ | 17 | help = [[ |
18 | Argument may be a local rockspec or rock file. | 18 | Arguments are local files, which may be rockspecs or rocks. |
19 | The flag --to indicates which server to use. | 19 | The flag --to indicates which server to use. |
20 | If not given, the default server set in the upload_server variable | 20 | If not given, the default server set in the upload_server variable |
21 | from the configuration file is used instead. | 21 | from the configuration file is used instead. |
@@ -23,16 +23,12 @@ The flag --no-refresh indicates the local cache should not be refreshed | |||
23 | prior to generation of the updated manifest. | 23 | prior to generation of the updated manifest. |
24 | ]] | 24 | ]] |
25 | 25 | ||
26 | local function add_file_to_server(refresh, rockfile, server, upload_server) | 26 | local function add_files_to_server(refresh, rockfiles, server, upload_server) |
27 | assert(type(refresh) == "boolean" or not refresh) | 27 | assert(type(refresh) == "boolean" or not refresh) |
28 | assert(type(rockfile) == "string") | 28 | assert(type(rockfiles) == "table") |
29 | assert(type(server) == "string") | 29 | assert(type(server) == "string") |
30 | assert(type(upload_server) == "table" or not upload_server) | 30 | assert(type(upload_server) == "table" or not upload_server) |
31 | 31 | ||
32 | if not fs.exists(rockfile) then | ||
33 | return nil, "Could not find "..rockfile | ||
34 | end | ||
35 | |||
36 | local download_url = server | 32 | local download_url = server |
37 | local login_url = nil | 33 | local login_url = nil |
38 | if upload_server then | 34 | if upload_server then |
@@ -43,8 +39,8 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) | |||
43 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp | 39 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp |
44 | end | 40 | end |
45 | end | 41 | end |
46 | 42 | ||
47 | local rockfile = fs.absolute_name(rockfile) | 43 | local at = fs.current_dir() |
48 | 44 | ||
49 | local local_cache, protocol, server_path, user, password | 45 | local local_cache, protocol, server_path, user, password |
50 | if refresh then | 46 | if refresh then |
@@ -58,9 +54,25 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) | |||
58 | if not login_url then | 54 | if not login_url then |
59 | login_url = protocol.."://"..server_path | 55 | login_url = protocol.."://"..server_path |
60 | end | 56 | end |
57 | |||
58 | fs.change_dir(at) | ||
59 | |||
60 | local files = {} | ||
61 | for i, rockfile in ipairs(rockfiles) do | ||
62 | if fs.exists(rockfile) then | ||
63 | print("Copying file "..rockfile.." to "..local_cache.."...") | ||
64 | local absolute = fs.absolute_name(rockfile) | ||
65 | fs.copy(absolute, local_cache) | ||
66 | table.insert(files, dir.base_name(absolute)) | ||
67 | else | ||
68 | print("File "..rockfile.." not found") | ||
69 | end | ||
70 | end | ||
71 | if #files == 0 then | ||
72 | return nil, "No files found" | ||
73 | end | ||
74 | |||
61 | fs.change_dir(local_cache) | 75 | fs.change_dir(local_cache) |
62 | print("Copying file "..rockfile.." to "..local_cache.."...") | ||
63 | fs.copy(rockfile, local_cache) | ||
64 | 76 | ||
65 | print("Updating manifest...") | 77 | print("Updating manifest...") |
66 | manif.make_manifest(local_cache) | 78 | manif.make_manifest(local_cache) |
@@ -76,16 +88,24 @@ local function add_file_to_server(refresh, rockfile, server, upload_server) | |||
76 | 88 | ||
77 | -- TODO abstract away explicit 'curl' call | 89 | -- TODO abstract away explicit 'curl' call |
78 | 90 | ||
79 | print ("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) | 91 | local cmd |
92 | if upload_server.sftp then | ||
93 | local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") | ||
94 | cmd = "scp manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 | ||
95 | else | ||
96 | cmd = "curl "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url | ||
97 | end | ||
80 | 98 | ||
81 | fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) | 99 | print(cmd) |
100 | fs.execute(cmd) | ||
82 | 101 | ||
83 | return true | 102 | return true |
84 | end | 103 | end |
85 | 104 | ||
86 | function run(...) | 105 | function run(...) |
87 | local flags, file = util.parse_flags(...) | 106 | local files = { util.parse_flags(...) } |
88 | if type(file) ~= "string" then | 107 | local flags = table.remove(files, 1) |
108 | if #files < 1 then | ||
89 | return nil, "Argument missing, see help." | 109 | return nil, "Argument missing, see help." |
90 | end | 110 | end |
91 | local server = flags["to"] | 111 | local server = flags["to"] |
@@ -93,6 +113,6 @@ function run(...) | |||
93 | if not server then | 113 | if not server then |
94 | return nil, "No server specified with --to and no default configured with upload_server." | 114 | return nil, "No server specified with --to and no default configured with upload_server." |
95 | end | 115 | end |
96 | return add_file_to_server(not flags["no-refresh"], file, server, cfg.upload_servers and cfg.upload_servers[server]) | 116 | return add_files_to_server(not flags["no-refresh"], files, server, cfg.upload_servers and cfg.upload_servers[server]) |
97 | end | 117 | end |
98 | 118 | ||