diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2010-09-08 17:27:43 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2010-09-08 17:32:26 -0300 |
commit | 70182a664e30bd73c72cd15e82118325d12d499b (patch) | |
tree | 4d4c7072cbd9bdd6f05d79172ca1a67d9ad3ce44 | |
parent | 61df38e58f67798be8957e80140fc7d1cfc60a15 (diff) | |
download | luarocks-70182a664e30bd73c72cd15e82118325d12d499b.tar.gz luarocks-70182a664e30bd73c72cd15e82118325d12d499b.tar.bz2 luarocks-70182a664e30bd73c72cd15e82118325d12d499b.zip |
Modify algorithm selection of rocks tree and add --local.
Drop old behavior in which the tree list was scanned to find the
first writable one (which meant users ended up installing rocks
locally). Now it always tries the last in the list (which is by
default the global one) and warns users when they have no write
permissions. (It picks the _last_ one so that the old behavior
when running sudo remains the same). Also add --local as a shorthand
to specify the local tree, as suggested by Steve Donovan.
-rw-r--r-- | src/luarocks/build.lua | 6 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 2 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 72 | ||||
-rw-r--r-- | src/luarocks/help.lua | 1 | ||||
-rw-r--r-- | src/luarocks/install.lua | 5 | ||||
-rw-r--r-- | src/luarocks/make.lua | 6 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 7 | ||||
-rw-r--r-- | src/luarocks/rep.lua | 6 |
8 files changed, 64 insertions, 41 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 62ac3808..c6c3a002 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -11,6 +11,7 @@ local fs = require("luarocks.fs") | |||
11 | local dir = require("luarocks.dir") | 11 | local dir = require("luarocks.dir") |
12 | local deps = require("luarocks.deps") | 12 | local deps = require("luarocks.deps") |
13 | local manif = require("luarocks.manif") | 13 | local manif = require("luarocks.manif") |
14 | local cfg = require("luarocks.cfg") | ||
14 | 15 | ||
15 | help_summary = "Build/compile a rock." | 16 | help_summary = "Build/compile a rock." |
16 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" | 17 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" |
@@ -269,6 +270,11 @@ function run(...) | |||
269 | end | 270 | end |
270 | assert(type(version) == "string" or not version) | 271 | assert(type(version) == "string" or not version) |
271 | 272 | ||
273 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
274 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
275 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
276 | end | ||
277 | |||
272 | if name:match("%.rockspec$") then | 278 | if name:match("%.rockspec$") then |
273 | return build_rockspec(name, true) | 279 | return build_rockspec(name, true) |
274 | elseif name:match("%.src%.rock$") then | 280 | elseif name:match("%.src%.rock$") then |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 261411b7..67cd17b7 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -83,7 +83,7 @@ end | |||
83 | 83 | ||
84 | -- Path configuration: | 84 | -- Path configuration: |
85 | 85 | ||
86 | local sys_config_file, home_config_file, home_tree | 86 | local sys_config_file, home_config_file |
87 | if detected.windows or detected.mingw32 then | 87 | if detected.windows or detected.mingw32 then |
88 | home = os.getenv("APPDATA") or "c:" | 88 | home = os.getenv("APPDATA") or "c:" |
89 | sys_config_file = "c:/luarocks/config.lua" | 89 | sys_config_file = "c:/luarocks/config.lua" |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index d501d121..71ded87d 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -33,6 +33,14 @@ local function is_writable(tree) | |||
33 | end | 33 | end |
34 | end | 34 | end |
35 | 35 | ||
36 | local function use_tree(tree) | ||
37 | cfg.root_dir = tree | ||
38 | cfg.rocks_dir = path.rocks_dir(tree) | ||
39 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
40 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
41 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
42 | end | ||
43 | |||
36 | --- Main command-line processor. | 44 | --- Main command-line processor. |
37 | -- Parses input arguments and calls the appropriate driver function | 45 | -- Parses input arguments and calls the appropriate driver function |
38 | -- to execute the action requested on the command-line, forwarding | 46 | -- to execute the action requested on the command-line, forwarding |
@@ -58,30 +66,39 @@ function run_command(...) | |||
58 | local nonflags = { util.parse_flags(unpack(args)) } | 66 | local nonflags = { util.parse_flags(unpack(args)) } |
59 | local flags = table.remove(nonflags, 1) | 67 | local flags = table.remove(nonflags, 1) |
60 | cfg.flags = flags | 68 | cfg.flags = flags |
69 | |||
70 | local command | ||
71 | |||
72 | if flags["version"] then | ||
73 | print(program_name.." "..cfg.program_version) | ||
74 | print(program_description) | ||
75 | print() | ||
76 | os.exit(0) | ||
77 | elseif flags["help"] or #nonflags == 0 then | ||
78 | command = "help" | ||
79 | args = nonflags | ||
80 | else | ||
81 | command = nonflags[1] | ||
82 | for i, arg in ipairs(args) do | ||
83 | if arg == command then | ||
84 | table.remove(args, i) | ||
85 | break | ||
86 | end | ||
87 | end | ||
88 | end | ||
89 | command = command:gsub("-", "_") | ||
61 | 90 | ||
62 | if flags["to"] then | 91 | if flags["to"] then |
63 | if flags["to"] == true then | 92 | if flags["to"] == true then |
64 | die("Argument error: use --to=<path>") | 93 | die("Argument error: use --to=<path>") |
65 | end | 94 | end |
66 | local root_dir = fs.absolute_name(flags["to"]) | 95 | local root_dir = fs.absolute_name(flags["to"]) |
67 | cfg.root_dir = root_dir | 96 | use_tree(root_dir) |
68 | cfg.rocks_dir = path.rocks_dir(root_dir) | 97 | elseif flags["local"] then |
69 | cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir) | 98 | use_tree(cfg.home_tree) |
70 | cfg.deploy_lua_dir = path.deploy_lua_dir(root_dir) | ||
71 | cfg.deploy_lib_dir = path.deploy_lib_dir(root_dir) | ||
72 | else | 99 | else |
73 | local trees = cfg.rocks_trees | 100 | local trees = cfg.rocks_trees |
74 | for i = #trees, 1, -1 do | 101 | use_tree(trees[#trees]) |
75 | local tree = trees[i] | ||
76 | if is_writable(tree) then | ||
77 | cfg.root_dir = tree | ||
78 | cfg.rocks_dir = path.rocks_dir(tree) | ||
79 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
80 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
81 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
82 | break | ||
83 | end | ||
84 | end | ||
85 | end | 102 | end |
86 | 103 | ||
87 | if type(cfg.root_dir) == "string" then | 104 | if type(cfg.root_dir) == "string" then |
@@ -111,34 +128,13 @@ function run_command(...) | |||
111 | end | 128 | end |
112 | cfg.rocks_servers = { flags["only-from"] } | 129 | cfg.rocks_servers = { flags["only-from"] } |
113 | end | 130 | end |
114 | 131 | ||
115 | local command | ||
116 | |||
117 | if flags["version"] then | ||
118 | print(program_name.." "..cfg.program_version) | ||
119 | print(program_description) | ||
120 | print() | ||
121 | os.exit(0) | ||
122 | elseif flags["help"] or #nonflags == 0 then | ||
123 | command = "help" | ||
124 | args = nonflags | ||
125 | else | ||
126 | command = nonflags[1] | ||
127 | for i, arg in ipairs(args) do | ||
128 | if arg == command then | ||
129 | table.remove(args, i) | ||
130 | break | ||
131 | end | ||
132 | end | ||
133 | end | ||
134 | |||
135 | if command ~= "help" then | 132 | if command ~= "help" then |
136 | for k, v in pairs(cmdline_vars) do | 133 | for k, v in pairs(cmdline_vars) do |
137 | cfg.variables[k] = v | 134 | cfg.variables[k] = v |
138 | end | 135 | end |
139 | end | 136 | end |
140 | 137 | ||
141 | command = command:gsub("-", "_") | ||
142 | if commands[command] then | 138 | if commands[command] then |
143 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 139 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) |
144 | die(debug.traceback("LuaRocks "..cfg.program_version | 140 | die(debug.traceback("LuaRocks "..cfg.program_version |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 04fea7ce..5162b917 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -40,6 +40,7 @@ can be overriden with VAR=VALUE assignments. | |||
40 | --only-from=<server> Fetch rocks/rockspecs from this server only | 40 | --only-from=<server> Fetch rocks/rockspecs from this server only |
41 | (overrides any entries in the config file) | 41 | (overrides any entries in the config file) |
42 | --to=<tree> Which tree to operate on. | 42 | --to=<tree> Which tree to operate on. |
43 | --local Use the tree in the user's home directory. | ||
43 | 44 | ||
44 | Supported commands: | 45 | Supported commands: |
45 | ]]) | 46 | ]]) |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 260c7751..74602f47 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -99,6 +99,11 @@ function run(...) | |||
99 | return nil, "Argument missing, see help." | 99 | return nil, "Argument missing, see help." |
100 | end | 100 | end |
101 | 101 | ||
102 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
103 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
104 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
105 | end | ||
106 | |||
102 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then | 107 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then |
103 | local build = require("luarocks.build") | 108 | local build = require("luarocks.build") |
104 | return build.run(name) | 109 | return build.run(name) |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index cb2ba374..ec3772ac 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -8,6 +8,7 @@ module("luarocks.make", package.seeall) | |||
8 | local build = require("luarocks.build") | 8 | local build = require("luarocks.build") |
9 | local fs = require("luarocks.fs") | 9 | local fs = require("luarocks.fs") |
10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
11 | local cfg = require("luarocks.cfg") | ||
11 | 12 | ||
12 | help_summary = "Compile package in current directory using a rockspec." | 13 | help_summary = "Compile package in current directory using a rockspec." |
13 | help_arguments = "[<rockspec>]" | 14 | help_arguments = "[<rockspec>]" |
@@ -30,6 +31,11 @@ To install rocks, you'll normally want to use the "install" and | |||
30 | function run(...) | 31 | function run(...) |
31 | local flags, rockspec = util.parse_flags(...) | 32 | local flags, rockspec = util.parse_flags(...) |
32 | assert(type(rockspec) == "string" or not rockspec) | 33 | assert(type(rockspec) == "string" or not rockspec) |
34 | |||
35 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
36 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
37 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
38 | end | ||
33 | 39 | ||
34 | if not rockspec then | 40 | if not rockspec then |
35 | local files = fs.list_dir(fs.current_dir()) | 41 | local files = fs.list_dir(fs.current_dir()) |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index afd299ae..d77f28fa 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
@@ -11,6 +11,7 @@ local path = require("luarocks.path") | |||
11 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
12 | local cfg = require("luarocks.cfg") | 12 | local cfg = require("luarocks.cfg") |
13 | local manif = require("luarocks.manif") | 13 | local manif = require("luarocks.manif") |
14 | local fs = require("luarocks.fs") | ||
14 | 15 | ||
15 | help_summary = "Uninstall a rock." | 16 | help_summary = "Uninstall a rock." |
16 | help_arguments = "[--force] <name> [<version>]" | 17 | help_arguments = "[--force] <name> [<version>]" |
@@ -81,6 +82,12 @@ function run(...) | |||
81 | if type(name) ~= "string" then | 82 | if type(name) ~= "string" then |
82 | return nil, "Argument missing, see help." | 83 | return nil, "Argument missing, see help." |
83 | end | 84 | end |
85 | |||
86 | if not flags["local"] and not fs.is_writable(cfg.rocks_dir) then | ||
87 | return nil, "Your user does not have write permissions in " .. cfg.rocks_dir .. | ||
88 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
89 | end | ||
90 | |||
84 | local results = {} | 91 | local results = {} |
85 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) | 92 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) |
86 | 93 | ||
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua index 5da5953f..322ab166 100644 --- a/src/luarocks/rep.lua +++ b/src/luarocks/rep.lua | |||
@@ -252,10 +252,11 @@ function delete_version(name, version) | |||
252 | local target = dir.path(deploy_dir, parent_path, file) | 252 | local target = dir.path(deploy_dir, parent_path, file) |
253 | local versioned = path.versioned_name(target, deploy_dir, name, version) | 253 | local versioned = path.versioned_name(target, deploy_dir, name, version) |
254 | if fs.exists(versioned) then | 254 | if fs.exists(versioned) then |
255 | fs.delete(versioned) | 255 | local ok = fs.delete(versioned) |
256 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 256 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
257 | if not ok then return nil, "Failed deleting "..versioned end | ||
257 | else | 258 | else |
258 | fs.delete(target) | 259 | local ok = fs.delete(target) |
259 | local next_name, next_version = manif.find_next_provider(target) | 260 | local next_name, next_version = manif.find_next_provider(target) |
260 | if next_name then | 261 | if next_name then |
261 | local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) | 262 | local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) |
@@ -263,6 +264,7 @@ function delete_version(name, version) | |||
263 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 264 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
264 | end | 265 | end |
265 | fs.remove_dir_tree_if_empty(dir.dir_name(target)) | 266 | fs.remove_dir_tree_if_empty(dir.dir_name(target)) |
267 | if not ok then return nil, "Failed deleting "..target end | ||
266 | end | 268 | end |
267 | return true | 269 | return true |
268 | end | 270 | end |