diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-02 11:30:19 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-03 10:44:51 -0300 |
| commit | 0b80c36bc1dfe85c882918b30f45d3a3fdf0e5ce (patch) | |
| tree | aab7efa0630572d4195fbd1eb1a5f770a33a1997 | |
| parent | dec452eb0a4019e59603e1167cd1161dc734c767 (diff) | |
| download | luarocks-0b80c36bc1dfe85c882918b30f45d3a3fdf0e5ce.tar.gz luarocks-0b80c36bc1dfe85c882918b30f45d3a3fdf0e5ce.tar.bz2 luarocks-0b80c36bc1dfe85c882918b30f45d3a3fdf0e5ce.zip | |
Simplify issue with superuser cache and avoid annoying message
When running as root, simply switch to use /var/cache/luarocks
as a cache.
| -rw-r--r-- | src/luarocks/cmd.lua | 28 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 20 | ||||
| -rw-r--r-- | src/luarocks/fs/unix.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 13 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 13 |
6 files changed, 20 insertions, 68 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index a46b0722..93bc5525 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -23,21 +23,6 @@ cmd.errorcodes = { | |||
| 23 | CRASH = 99 | 23 | CRASH = 99 |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | local function is_ownership_ok(directory) | ||
| 27 | local me = fs.current_user() | ||
| 28 | if not me then | ||
| 29 | return nil, "can't determine current user's name" | ||
| 30 | end | ||
| 31 | for _ = 1,3 do -- try up to grandparent | ||
| 32 | local owner = fs.attributes(directory, "owner") | ||
| 33 | if owner then | ||
| 34 | return owner == me | ||
| 35 | end | ||
| 36 | directory = dir.dir_name(directory) | ||
| 37 | end | ||
| 38 | return false | ||
| 39 | end | ||
| 40 | |||
| 41 | local function check_popen() | 26 | local function check_popen() |
| 42 | local popen_ok, popen_result = pcall(io.popen, "") | 27 | local popen_ok, popen_result = pcall(io.popen, "") |
| 43 | if popen_ok then | 28 | if popen_ok then |
| @@ -393,16 +378,9 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 393 | end | 378 | end |
| 394 | end | 379 | end |
| 395 | 380 | ||
| 396 | local user_owns_local_cache = is_ownership_ok(cfg.local_cache) | 381 | -- if running as superuser, use system cache dir |
| 397 | if user_owns_local_cache == false then | 382 | if not cfg.home_tree then |
| 398 | util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory ".. | 383 | cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") |
| 399 | "is not owned by the current user and the cache has been disabled. ".. | ||
| 400 | "Please check the permissions and owner of that directory. ".. | ||
| 401 | (cfg.is_platform("unix") | ||
| 402 | and ("If executing "..util.this_program("luarocks").." with sudo, you may want sudo's -H flag.") | ||
| 403 | or "")) | ||
| 404 | cfg.local_cache = fs.make_temp_dir("local_cache") | ||
| 405 | util.schedule_function(fs.delete, cfg.local_cache) | ||
| 406 | end | 384 | end |
| 407 | 385 | ||
| 408 | if commands[command] then | 386 | if commands[command] then |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 859f77e0..0c2e3f67 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -259,15 +259,12 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
| 259 | MD5SUM = "md5sum", | 259 | MD5SUM = "md5sum", |
| 260 | OPENSSL = "openssl", | 260 | OPENSSL = "openssl", |
| 261 | MD5 = "md5", | 261 | MD5 = "md5", |
| 262 | STAT = "stat", | ||
| 263 | TOUCH = "touch", | 262 | TOUCH = "touch", |
| 264 | 263 | ||
| 265 | CMAKE = "cmake", | 264 | CMAKE = "cmake", |
| 266 | SEVENZ = "7z", | 265 | SEVENZ = "7z", |
| 267 | 266 | ||
| 268 | RSYNCFLAGS = "--exclude=.git -Oavz", | 267 | RSYNCFLAGS = "--exclude=.git -Oavz", |
| 269 | STATPERMFLAG = "-c '%a'", | ||
| 270 | STATOWNERFLAG = "-c '%U'", | ||
| 271 | CURLNOCERTFLAG = "", | 268 | CURLNOCERTFLAG = "", |
| 272 | WGETNOCERTFLAG = "", | 269 | WGETNOCERTFLAG = "", |
| 273 | }, | 270 | }, |
| @@ -419,8 +416,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
| 419 | 416 | ||
| 420 | if platforms.bsd then | 417 | if platforms.bsd then |
| 421 | defaults.variables.MAKE = "gmake" | 418 | defaults.variables.MAKE = "gmake" |
| 422 | defaults.variables.STATPERMFLAG = "-f '%OLp'" | ||
| 423 | defaults.variables.STATOWNERFLAG = "-f '%Su'" | ||
| 424 | end | 419 | end |
| 425 | 420 | ||
| 426 | if platforms.macosx then | 421 | if platforms.macosx then |
| @@ -428,8 +423,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
| 428 | defaults.external_lib_extension = "dylib" | 423 | defaults.external_lib_extension = "dylib" |
| 429 | defaults.arch = "macosx-"..target_cpu | 424 | defaults.arch = "macosx-"..target_cpu |
| 430 | defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" | 425 | defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" |
| 431 | defaults.variables.STAT = "/usr/bin/stat" | ||
| 432 | defaults.variables.STATFLAG = "-f '%A'" | ||
| 433 | local version = util.popen_read("sw_vers -productVersion") | 426 | local version = util.popen_read("sw_vers -productVersion") |
| 434 | version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 | 427 | version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 |
| 435 | if version >= 10 then | 428 | if version >= 10 then |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index c3bf87e3..6ad2b1b8 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -243,6 +243,10 @@ function fs_lua.filter_file(fn, input_filename, output_filename) | |||
| 243 | return true | 243 | return true |
| 244 | end | 244 | end |
| 245 | 245 | ||
| 246 | function fs_lua.system_temp_dir() | ||
| 247 | return os.getenv("TMPDIR") or os.getenv("TEMP") or "/tmp" | ||
| 248 | end | ||
| 249 | |||
| 246 | --------------------------------------------------------------------- | 250 | --------------------------------------------------------------------- |
| 247 | -- LuaFileSystem functions | 251 | -- LuaFileSystem functions |
| 248 | --------------------------------------------------------------------- | 252 | --------------------------------------------------------------------- |
| @@ -986,18 +990,6 @@ function fs_lua.set_permissions(filename, mode, scope) | |||
| 986 | return err == 0 | 990 | return err == 0 |
| 987 | end | 991 | end |
| 988 | 992 | ||
| 989 | function fs_lua.attributes(file, attrtype) | ||
| 990 | if attrtype == "permissions" then | ||
| 991 | return posix.stat(file, "mode") or nil | ||
| 992 | elseif attrtype == "owner" then | ||
| 993 | local uid = posix.stat(file, "uid") | ||
| 994 | if not uid then return nil end | ||
| 995 | return posix.getpwuid(uid).pw_name or nil | ||
| 996 | else | ||
| 997 | return nil | ||
| 998 | end | ||
| 999 | end | ||
| 1000 | |||
| 1001 | function fs_lua.current_user() | 993 | function fs_lua.current_user() |
| 1002 | return posix.getpwuid(posix.geteuid()).pw_name | 994 | return posix.getpwuid(posix.geteuid()).pw_name |
| 1003 | end | 995 | end |
| @@ -1013,7 +1005,7 @@ function fs_lua.make_temp_dir(name_pattern) | |||
| 1013 | assert(type(name_pattern) == "string") | 1005 | assert(type(name_pattern) == "string") |
| 1014 | name_pattern = dir.normalize(name_pattern) | 1006 | name_pattern = dir.normalize(name_pattern) |
| 1015 | 1007 | ||
| 1016 | return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name_pattern:gsub("/", "_") .. "-XXXXXX") | 1008 | return posix.mkdtemp(fs.system_temp_dir() .. "/luarocks_" .. name_pattern:gsub("/", "_") .. "-XXXXXX") |
| 1017 | end | 1009 | end |
| 1018 | 1010 | ||
| 1019 | end -- if posix.mkdtemp | 1011 | end -- if posix.mkdtemp |
| @@ -1030,7 +1022,7 @@ function fs_lua.make_temp_dir(name_pattern) | |||
| 1030 | assert(type(name_pattern) == "string") | 1022 | assert(type(name_pattern) == "string") |
| 1031 | name_pattern = dir.normalize(name_pattern) | 1023 | name_pattern = dir.normalize(name_pattern) |
| 1032 | 1024 | ||
| 1033 | local pattern = (os.getenv("TMPDIR") or os.getenv("TEMP") or "/tmp") .. "/luarocks_" .. name_pattern:gsub("/", "_") .. "-" | 1025 | local pattern = fs.system_temp_dir() .. "/luarocks_" .. name_pattern:gsub("/", "_") .. "-" |
| 1034 | 1026 | ||
| 1035 | while true do | 1027 | while true do |
| 1036 | local name = pattern .. tostring(math.random(10000000)) | 1028 | local name = pattern .. tostring(math.random(10000000)) |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 849259e8..075581e4 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
| @@ -245,4 +245,11 @@ function unix.is_file(file) | |||
| 245 | return false | 245 | return false |
| 246 | end | 246 | end |
| 247 | 247 | ||
| 248 | function unix.system_cache_dir() | ||
| 249 | if fs.is_dir("/var/cache") then | ||
| 250 | return "/var/cache" | ||
| 251 | end | ||
| 252 | return dir.path(fs.system_temp_dir(), "cache") | ||
| 253 | end | ||
| 254 | |||
| 248 | return unix | 255 | return unix |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 9a2f99a7..65b5681c 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -233,19 +233,6 @@ function tools.set_permissions(filename, mode, scope) | |||
| 233 | return fs.execute(vars.CHMOD, perms, filename) | 233 | return fs.execute(vars.CHMOD, perms, filename) |
| 234 | end | 234 | end |
| 235 | 235 | ||
| 236 | function tools.attributes(filename, attrtype) | ||
| 237 | local flag = ((attrtype == "permissions") and vars.STATPERMFLAG) | ||
| 238 | or ((attrtype == "owner") and vars.STATOWNERFLAG) | ||
| 239 | if not flag then return "" end | ||
| 240 | local pipe = io.popen(fs.quiet_stderr(vars.STAT.." "..flag.." "..fs.Q(filename))) | ||
| 241 | local ret = pipe:read("*l") | ||
| 242 | pipe:close() | ||
| 243 | if ret == "" then | ||
| 244 | return nil | ||
| 245 | end | ||
| 246 | return ret | ||
| 247 | end | ||
| 248 | |||
| 249 | function tools.browser(url) | 236 | function tools.browser(url) |
| 250 | return fs.execute(cfg.web_browser, url) | 237 | return fs.execute(cfg.web_browser, url) |
| 251 | end | 238 | end |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 498eceb7..f66466fc 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -209,15 +209,6 @@ function win32.copy_binary(filename, dest) | |||
| 209 | return true | 209 | return true |
| 210 | end | 210 | end |
| 211 | 211 | ||
| 212 | function win32.attributes(filename, attrtype) | ||
| 213 | if attrtype == "permissions" then | ||
| 214 | return "" -- FIXME | ||
| 215 | elseif attrtype == "owner" then | ||
| 216 | return os.getenv("USERNAME") -- FIXME popen_read('powershell -Command "& {(get-acl '..filename..').owner}"'):gsub("^[^\\]*\\", "") | ||
| 217 | end | ||
| 218 | return nil | ||
| 219 | end | ||
| 220 | |||
| 221 | --- Move a file on top of the other. | 212 | --- Move a file on top of the other. |
| 222 | -- The new file ceases to exist under its original name, | 213 | -- The new file ceases to exist under its original name, |
| 223 | -- and takes over the name of the old file. | 214 | -- and takes over the name of the old file. |
| @@ -329,4 +320,8 @@ function win32.export_cmd(var, val) | |||
| 329 | return ("SET %s=%s"):format(var, val) | 320 | return ("SET %s=%s"):format(var, val) |
| 330 | end | 321 | end |
| 331 | 322 | ||
| 323 | function win32.system_cache_dir() | ||
| 324 | return dir.path(fs.system_temp_dir(), "cache") | ||
| 325 | end | ||
| 326 | |||
| 332 | return win32 | 327 | return win32 |
