From 419686e343b0bf07f962b3d0ed1a4244eb7213bb Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 26 Mar 2012 11:44:40 -0300 Subject: Improve check for permissions, and use standardized check in 'remove' command as well. --- src/luarocks/fs/lua.lua | 22 ++++++++++++++++++---- src/luarocks/remove.lua | 8 +++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 191ef35c..67c3ce0f 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -654,9 +654,23 @@ end -- plus an error message. function check_command_permissions(flags) local root_dir = path.root_dir(cfg.rocks_dir) - if not flags["local"] and not (fs.is_writable(root_dir) or fs.is_writable(dir.dir_name(root_dir))) then - return nil, "Your user does not have write permissions in " .. root_dir .. - " \n-- you may want to run as a privileged user or use your local tree with --local." + local ok = true + local err = "" + for _, dir in ipairs { cfg.rocks_dir, root_dir, dir.dir_name(root_dir) } do + if fs.exists(dir) and not fs.is_writable(dir) then + ok = false + err = "Your user does not have write permissions in " .. dir + break + end + end + if ok then + return true + else + if flags["local"] then + err = err .. " \n-- please check your permissions." + else + err = err .. " \n-- you may want to run as a privileged user or use your local tree with --local." + end + return nil, err end - return true end diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index caa683ee..b22d1ab6 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -82,11 +82,9 @@ function run(...) if type(name) ~= "string" then return nil, "Argument missing, see help." end - - if not flags["local"] and not fs.is_writable(cfg.rocks_dir) then - return nil, "Your user does not have write permissions in " .. cfg.rocks_dir .. - " \n-- you may want to run as a privileged user or use your local tree with --local." - end + + local ok, err = fs.check_command_permissions(flags) + if not ok then return nil, err end local results = {} search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) -- cgit v1.2.3-55-g6feb