diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-13 18:45:01 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-13 18:45:01 +0000 |
| commit | 890c6698f94cf0d4a69cd5e85fdc5ff4bcb79414 (patch) | |
| tree | e950473a5118b060aa4b6dba8030b526c77cabb2 /src | |
| parent | 9796a4e66ab99202ec6edf72d8842753b62f883f (diff) | |
| download | luarocks-890c6698f94cf0d4a69cd5e85fdc5ff4bcb79414.tar.gz luarocks-890c6698f94cf0d4a69cd5e85fdc5ff4bcb79414.tar.bz2 luarocks-890c6698f94cf0d4a69cd5e85fdc5ff4bcb79414.zip | |
Support uploads via sftp (needed for luarocks.org repositories...)
git-svn-id: http://luarocks.org/svn/luarocks/trunk@96 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/add.lua | 40 |
1 files changed, 32 insertions, 8 deletions
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") | |||
| 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>] {<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 | Argument may be a local rockspec or rock file. |
| 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. |
| 22 | The flag --no-refresh indicates the local cache should not be refreshed | ||
| 23 | prior to generation of the updated manifest. | ||
| 22 | ]] | 24 | ]] |
| 23 | 25 | ||
| 24 | local function add_file_to_server(refresh, rockfile, server) | 26 | local function add_file_to_server(refresh, rockfile, server, upload_server) |
| 27 | assert(type(refresh) == "boolean" or not refresh) | ||
| 28 | assert(type(rockfile) == "string") | ||
| 29 | assert(type(server) == "string") | ||
| 30 | assert(type(upload_server) == "table" or not upload_server) | ||
| 31 | |||
| 25 | if not fs.exists(rockfile) then | 32 | if not fs.exists(rockfile) then |
| 26 | return nil, "Could not find "..rockfile | 33 | return nil, "Could not find "..rockfile |
| 27 | end | 34 | end |
| 35 | |||
| 36 | local download_url = server | ||
| 37 | local login_url = nil | ||
| 38 | if upload_server then | ||
| 39 | if upload_server.http then download_url = "http://"..upload_server.http | ||
| 40 | elseif upload_server.ftp then download_url = "ftp://"..upload_server.ftp | ||
| 41 | end | ||
| 42 | if upload_server.ftp then login_url = "ftp://"..upload_server.ftp | ||
| 43 | elseif upload_server.sftp then login_url = "sftp://"..upload_server.sftp | ||
| 44 | end | ||
| 45 | end | ||
| 28 | 46 | ||
| 29 | local rockfile = fs.absolute_name(rockfile) | 47 | local rockfile = fs.absolute_name(rockfile) |
| 30 | 48 | ||
| 31 | local local_cache, protocol, server_path, user, password | 49 | local local_cache, protocol, server_path, user, password |
| 32 | if refresh then | 50 | if refresh then |
| 33 | local_cache, protocol, server_path, user, password = cache.refresh_local_cache(server, cfg.upload_user, cfg.upload_password) | 51 | local_cache, protocol, server_path, user, password = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) |
| 34 | else | 52 | else |
| 35 | local_cache, protocol, server_path, user, password = cache.split_server_url(server, cfg.upload_user, cfg.upload_password) | 53 | local_cache, protocol, server_path, user, password = cache.split_server_url(download_url, cfg.upload_user, cfg.upload_password) |
| 54 | end | ||
| 55 | if not login_url then | ||
| 56 | login_url = protocol.."://"..server_path | ||
| 36 | end | 57 | end |
| 37 | fs.change_dir(local_cache) | 58 | fs.change_dir(local_cache) |
| 38 | print("Copying file "..rockfile.." to "..local_cache.."...") | 59 | print("Copying file "..rockfile.." to "..local_cache.."...") |
| @@ -46,12 +67,15 @@ local function add_file_to_server(refresh, rockfile, server) | |||
| 46 | local login_info = "" | 67 | local login_info = "" |
| 47 | if user then login_info = " -u "..user end | 68 | if user then login_info = " -u "..user end |
| 48 | if password then login_info = login_info..":"..password end | 69 | if password then login_info = login_info..":"..password end |
| 49 | if not server_path:match("/$") then | 70 | if not login_url:match("/$") then |
| 50 | server_path = server_path .. "/" | 71 | login_url = login_url .. "/" |
| 51 | end | 72 | end |
| 52 | 73 | ||
| 53 | -- TODO abstract away explicit 'curl' call | 74 | -- TODO abstract away explicit 'curl' call |
| 54 | fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) | 75 | |
| 76 | print ("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) | ||
| 77 | |||
| 78 | fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..login_url) | ||
| 55 | 79 | ||
| 56 | return true | 80 | return true |
| 57 | end | 81 | end |
| @@ -69,6 +93,6 @@ function run(...) | |||
| 69 | if cfg.upload_aliases then | 93 | if cfg.upload_aliases then |
| 70 | server = cfg.upload_aliases[server] or server | 94 | server = cfg.upload_aliases[server] or server |
| 71 | end | 95 | end |
| 72 | return add_file_to_server(not flags["no-refresh"], file, server) | 96 | return add_file_to_server(not flags["no-refresh"], file, server, cfg.upload_servers and cfg.upload_servers[server]) |
| 73 | end | 97 | end |
| 74 | 98 | ||
