aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2012-03-26 11:44:40 -0300
committerHisham Muhammad <hisham@gobolinux.org>2012-03-26 11:45:13 -0300
commit419686e343b0bf07f962b3d0ed1a4244eb7213bb (patch)
tree52522962891dae275db8fe61bab4b163d7aecdb0
parentbcca1a559b5b4e0c6d53070e4e6926504f7d5abf (diff)
downloadluarocks-419686e343b0bf07f962b3d0ed1a4244eb7213bb.tar.gz
luarocks-419686e343b0bf07f962b3d0ed1a4244eb7213bb.tar.bz2
luarocks-419686e343b0bf07f962b3d0ed1a4244eb7213bb.zip
Improve check for permissions, and use standardized check in 'remove' command as well.
-rw-r--r--src/luarocks/fs/lua.lua22
-rw-r--r--src/luarocks/remove.lua8
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
654-- plus an error message. 654-- plus an error message.
655function check_command_permissions(flags) 655function check_command_permissions(flags)
656 local root_dir = path.root_dir(cfg.rocks_dir) 656 local root_dir = path.root_dir(cfg.rocks_dir)
657 if not flags["local"] and not (fs.is_writable(root_dir) or fs.is_writable(dir.dir_name(root_dir))) then 657 local ok = true
658 return nil, "Your user does not have write permissions in " .. root_dir .. 658 local err = ""
659 " \n-- you may want to run as a privileged user or use your local tree with --local." 659 for _, dir in ipairs { cfg.rocks_dir, root_dir, dir.dir_name(root_dir) } do
660 if fs.exists(dir) and not fs.is_writable(dir) then
661 ok = false
662 err = "Your user does not have write permissions in " .. dir
663 break
664 end
665 end
666 if ok then
667 return true
668 else
669 if flags["local"] then
670 err = err .. " \n-- please check your permissions."
671 else
672 err = err .. " \n-- you may want to run as a privileged user or use your local tree with --local."
673 end
674 return nil, err
660 end 675 end
661 return true
662end 676end
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(...)
82 if type(name) ~= "string" then 82 if type(name) ~= "string" then
83 return nil, "Argument missing, see help." 83 return nil, "Argument missing, see help."
84 end 84 end
85 85
86 if not flags["local"] and not fs.is_writable(cfg.rocks_dir) then 86 local ok, err = fs.check_command_permissions(flags)
87 return nil, "Your user does not have write permissions in " .. cfg.rocks_dir .. 87 if not ok then return nil, err end
88 " \n-- you may want to run as a privileged user or use your local tree with --local."
89 end
90 88
91 local results = {} 89 local results = {}
92 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) 90 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))