diff options
-rw-r--r-- | src/luarocks/fs/lua.lua | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 5c369648..454d8e46 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -1173,6 +1173,27 @@ function fs_lua.move(src, dest, perms) | |||
1173 | return true | 1173 | return true |
1174 | end | 1174 | end |
1175 | 1175 | ||
1176 | local function get_local_tree() | ||
1177 | for _, tree in ipairs(cfg.rocks_trees) do | ||
1178 | if type(tree) == "table" and tree.name == "user" then | ||
1179 | return fs.absolute_name(tree.root) | ||
1180 | end | ||
1181 | end | ||
1182 | end | ||
1183 | |||
1184 | local function is_local_tree_in_env(local_tree) | ||
1185 | local lua_path | ||
1186 | if _VERSION == "Lua 5.1" then | ||
1187 | lua_path = os.getenv("LUA_PATH") | ||
1188 | else | ||
1189 | lua_path = os.getenv("LUA_PATH_" .. _VERSION:sub(5):gsub("%.", "_")) | ||
1190 | or os.getenv("LUA_PATH") | ||
1191 | end | ||
1192 | if lua_path and lua_path:match(local_tree, 1, true) then | ||
1193 | return true | ||
1194 | end | ||
1195 | end | ||
1196 | |||
1176 | --- Check if user has write permissions for the command. | 1197 | --- Check if user has write permissions for the command. |
1177 | -- Assumes the configuration variables under cfg have been previously set up. | 1198 | -- Assumes the configuration variables under cfg have been previously set up. |
1178 | -- @param args table: the args table passed to run() drivers. | 1199 | -- @param args table: the args table passed to run() drivers. |
@@ -1202,7 +1223,7 @@ function fs_lua.check_command_permissions(args) | |||
1202 | until parent == root or fs.exists(parent) | 1223 | until parent == root or fs.exists(parent) |
1203 | if not fs.is_writable(parent) then | 1224 | if not fs.is_writable(parent) then |
1204 | ok = false | 1225 | ok = false |
1205 | err = directory.." does not exist and your user does not have write permissions in " .. parent | 1226 | err = directory.." does not exist\nand your user does not have write permissions in " .. parent |
1206 | break | 1227 | break |
1207 | end | 1228 | end |
1208 | end | 1229 | end |
@@ -1212,9 +1233,20 @@ function fs_lua.check_command_permissions(args) | |||
1212 | return true | 1233 | return true |
1213 | else | 1234 | else |
1214 | if args["local"] or cfg.local_by_default then | 1235 | if args["local"] or cfg.local_by_default then |
1215 | err = err .. " \n-- please check your permissions." | 1236 | err = err .. "\n\nPlease check your permissions.\n" |
1216 | else | 1237 | else |
1217 | err = err .. " \n-- you may want to run as a privileged user or use your local tree with --local." | 1238 | local local_tree = get_local_tree() |
1239 | if local_tree then | ||
1240 | err = err .. "\n\nYou may want to run as a privileged user," | ||
1241 | .. "\nor use --local to install into your local tree at " .. local_tree | ||
1242 | .. "\nor run 'luarocks config local_by_default true' to make --local the default.\n" | ||
1243 | |||
1244 | if not is_local_tree_in_env(local_tree) then | ||
1245 | err = err .. "\n(You may need to configure your Lua package paths\nto use the local tree, see 'luarocks path --help')\n" | ||
1246 | end | ||
1247 | else | ||
1248 | err = err .. "\n\nYou may want to run as a privileged user.\n" | ||
1249 | end | ||
1218 | end | 1250 | end |
1219 | return nil, err | 1251 | return nil, err |
1220 | end | 1252 | end |