diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2010-11-18 22:23:47 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2010-11-18 22:23:47 -0200 |
commit | 7f79d5a020d2345704193aeb3cb17aee99c87b4a (patch) | |
tree | 6dd50587e8b0b2cf1eed0a232fd47b0eb1a8e51f | |
parent | 870d63b8f6ef610161938c253e9bf3df0faa9fe8 (diff) | |
download | luarocks-7f79d5a020d2345704193aeb3cb17aee99c87b4a.tar.gz luarocks-7f79d5a020d2345704193aeb3cb17aee99c87b4a.tar.bz2 luarocks-7f79d5a020d2345704193aeb3cb17aee99c87b4a.zip |
Fix usage of cfg.root_dir, which can now be either a string or a table.
Thanks to Fabio Mascarenhas for the heads-up.
-rw-r--r-- | src/luarocks/build.lua | 9 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 15 | ||||
-rw-r--r-- | src/luarocks/install.lua | 9 | ||||
-rw-r--r-- | src/luarocks/make.lua | 6 | ||||
-rw-r--r-- | src/luarocks/util.lua | 1 |
5 files changed, 25 insertions, 15 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 6eca0c3e..e6afde54 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -235,8 +235,9 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) | |||
235 | license = ("(license: "..rockspec.description.license..")") | 235 | license = ("(license: "..rockspec.description.license..")") |
236 | end | 236 | end |
237 | 237 | ||
238 | local root_dir = path.root_dir(cfg.rocks_dir) | ||
238 | print() | 239 | print() |
239 | print(name.." "..version.." is now built and installed in "..cfg.root_dir.." "..license) | 240 | print(name.." "..version.." is now built and installed in "..root_dir.." "..license) |
240 | 241 | ||
241 | util.remove_scheduled_function(rollback) | 242 | util.remove_scheduled_function(rollback) |
242 | return true | 243 | return true |
@@ -278,10 +279,8 @@ function run(...) | |||
278 | end | 279 | end |
279 | assert(type(version) == "string" or not version) | 280 | assert(type(version) == "string" or not version) |
280 | 281 | ||
281 | if not flags["local"] and (fs.exists(cfg.root_dir) and not fs.is_writable(cfg.root_dir)) then | 282 | local ok, err = fs.check_command_permissions(flags) |
282 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | 283 | if not ok then return nil, err end |
283 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
284 | end | ||
285 | 284 | ||
286 | if name:match("%.rockspec$") then | 285 | if name:match("%.rockspec$") then |
287 | return build_rockspec(name, true) | 286 | return build_rockspec(name, true) |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 70df65be..5b3efd94 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -8,6 +8,7 @@ local fs = require("luarocks.fs") | |||
8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
11 | local path = require("luarocks.path") | ||
11 | 12 | ||
12 | local socket_ok, http = pcall(require, "socket.http") | 13 | local socket_ok, http = pcall(require, "socket.http") |
13 | local _, ftp = pcall(require, "socket.ftp") | 14 | local _, ftp = pcall(require, "socket.ftp") |
@@ -615,3 +616,17 @@ function move(src, dest) | |||
615 | end | 616 | end |
616 | return true | 617 | return true |
617 | end | 618 | end |
619 | |||
620 | --- Check if user has write permissions for the command. | ||
621 | -- Assumes the configuration variables under cfg have been previously set up. | ||
622 | -- @param flags table: the flags table passed to run() drivers. | ||
623 | -- @return boolean or (boolean, string): true on success, false on failure, | ||
624 | -- plus an error message. | ||
625 | function check_command_permissions(flags) | ||
626 | local root_dir = path.root_dir(cfg.rocks_dir) | ||
627 | if not flags["local"] and not fs.is_writable(root_dir) then | ||
628 | return nil, "Your user does not have write permissions in " .. root_dir .. | ||
629 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
630 | end | ||
631 | return true | ||
632 | end | ||
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index f9f27ccf..016e73bb 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -84,8 +84,9 @@ function install_binary_rock(rock_file) | |||
84 | license = ("(license: "..rockspec.description.license..")") | 84 | license = ("(license: "..rockspec.description.license..")") |
85 | end | 85 | end |
86 | 86 | ||
87 | local root_dir = path.root_dir(cfg.rocks_dir) | ||
87 | print() | 88 | print() |
88 | print(name.." "..version.." is now installed in "..cfg.root_dir.." "..license) | 89 | print(name.." "..version.." is now installed in "..root_dir.." "..license) |
89 | 90 | ||
90 | util.remove_scheduled_function(rollback) | 91 | util.remove_scheduled_function(rollback) |
91 | return true | 92 | return true |
@@ -107,10 +108,8 @@ function run(...) | |||
107 | return nil, "Argument missing, see help." | 108 | return nil, "Argument missing, see help." |
108 | end | 109 | end |
109 | 110 | ||
110 | if not flags["local"] and (fs.exists(cfg.root_dir) and not fs.is_writable(cfg.root_dir)) then | 111 | local ok, err = fs.check_command_permissions(flags) |
111 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | 112 | if not ok then return nil, err end |
112 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
113 | end | ||
114 | 113 | ||
115 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then | 114 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then |
116 | local build = require("luarocks.build") | 115 | local build = require("luarocks.build") |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index ec3772ac..4af5a16c 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -32,10 +32,8 @@ function run(...) | |||
32 | local flags, rockspec = util.parse_flags(...) | 32 | local flags, rockspec = util.parse_flags(...) |
33 | assert(type(rockspec) == "string" or not rockspec) | 33 | assert(type(rockspec) == "string" or not rockspec) |
34 | 34 | ||
35 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | 35 | local ok, err = fs.check_command_permissions(flags) |
36 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | 36 | if not ok then return nil, err end |
37 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
38 | end | ||
39 | 37 | ||
40 | if not rockspec then | 38 | if not rockspec then |
41 | local files = fs.list_dir(fs.current_dir()) | 39 | local files = fs.list_dir(fs.current_dir()) |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index ed70b2ba..10fc1e36 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -362,4 +362,3 @@ function show_table(t, name, indent) | |||
362 | addtocart(t, name, indent) | 362 | addtocart(t, name, indent) |
363 | return cart .. autoref | 363 | return cart .. autoref |
364 | end | 364 | end |
365 | |||