Mercurial > repo
comparison share/lua/5.2/luarocks/admin_remove.lua @ 1132:d137f631bad5
<GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
author | HackBot |
---|---|
date | Fri, 14 Dec 2012 22:24:27 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1131:ff65dfb63263 | 1132:d137f631bad5 |
---|---|
1 | |
2 --- Module implementing the luarocks-admin "remove" command. | |
3 -- Removes a rock or rockspec from a rocks server. | |
4 module("luarocks.admin_remove", package.seeall) | |
5 | |
6 local cfg = require("luarocks.cfg") | |
7 local util = require("luarocks.util") | |
8 local fetch = require("luarocks.fetch") | |
9 local dir = require("luarocks.dir") | |
10 local manif = require("luarocks.manif") | |
11 local index = require("luarocks.index") | |
12 local fs = require("luarocks.fs") | |
13 local cache = require("luarocks.cache") | |
14 | |
15 help_summary = "Remove a rock or rockspec from a rocks server." | |
16 help_arguments = "[--from=<server>] [--no-refresh] {<rockspec>|<rock>...}" | |
17 help = [[ | |
18 Arguments are local files, which may be rockspecs or rocks. | |
19 The flag --from indicates which server to use. | |
20 If not given, the default server set in the upload_server variable | |
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. | |
24 ]] | |
25 | |
26 local function remove_files_from_server(refresh, rockfiles, server, upload_server) | |
27 assert(type(refresh) == "boolean" or not refresh) | |
28 assert(type(rockfiles) == "table") | |
29 assert(type(server) == "string") | |
30 assert(type(upload_server) == "table" or not upload_server) | |
31 | |
32 local download_url, login_url = cache.get_server_urls(server, upload_server) | |
33 local at = fs.current_dir() | |
34 local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url | |
35 | |
36 local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) | |
37 if not local_cache then | |
38 return nil, protocol | |
39 end | |
40 if protocol ~= "rsync" then | |
41 return nil, "This command requires 'rsync', check your configuration." | |
42 end | |
43 | |
44 fs.change_dir(at) | |
45 | |
46 local nr_files = 0 | |
47 for i, rockfile in ipairs(rockfiles) do | |
48 local basename = dir.base_name(rockfile) | |
49 local file = dir.path(local_cache, basename) | |
50 util.printout("Removing file "..file.."...") | |
51 if fs.delete(file) then | |
52 nr_files = nr_files + 1 | |
53 else | |
54 util.printerr("Failed removing "..file) | |
55 end | |
56 end | |
57 if nr_files == 0 then | |
58 return nil, "No files removed." | |
59 end | |
60 | |
61 fs.change_dir(local_cache) | |
62 | |
63 util.printout("Updating manifest...") | |
64 manif.make_manifest(local_cache, "one") | |
65 util.printout("Updating index.html...") | |
66 index.make_index(local_cache) | |
67 | |
68 local srv, path = server_path:match("([^/]+)(/.+)") | |
69 local cmd = "rsync -Oavz --delete -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" | |
70 | |
71 util.printout(cmd) | |
72 fs.execute(cmd) | |
73 | |
74 return true | |
75 end | |
76 | |
77 function run(...) | |
78 local files = { util.parse_flags(...) } | |
79 local flags = table.remove(files, 1) | |
80 if #files < 1 then | |
81 return nil, "Argument missing, see help." | |
82 end | |
83 local server, server_table = cache.get_upload_server(flags["server"]) | |
84 if not server then return nil, server_table end | |
85 return remove_files_from_server(not flags["no-refresh"], files, server, server_table) | |
86 end | |
87 |