diff options
author | Hisham <hisham@gobolinux.org> | 2017-01-06 17:30:38 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-09-12 20:35:15 -0300 |
commit | 21cd04b1251866aed553cd535e2d129362f11aa2 (patch) | |
tree | 7eaa3163e01c8a796074d688c9fc55e6d30b99e4 /src | |
parent | b9cc2c906c89a022a0b79515b27d6cce61517f2b (diff) | |
download | luarocks-21cd04b1251866aed553cd535e2d129362f11aa2.tar.gz luarocks-21cd04b1251866aed553cd535e2d129362f11aa2.tar.bz2 luarocks-21cd04b1251866aed553cd535e2d129362f11aa2.zip |
Check ownership of cache directory and emit a warning.
This prevents `sudo luarocks` to take over ownership of
the user's ~/.cache/luarocks directory.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cfg.lua | 6 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 12 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 16 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 7 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 11 |
6 files changed, 47 insertions, 9 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 1141acf6..858a87fe 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -409,7 +409,8 @@ local defaults = { | |||
409 | SEVENZ = "7z", | 409 | SEVENZ = "7z", |
410 | 410 | ||
411 | RSYNCFLAGS = "--exclude=.git -Oavz", | 411 | RSYNCFLAGS = "--exclude=.git -Oavz", |
412 | STATFLAG = "-c '%a'", | 412 | STATPERMFLAG = "-c '%a'", |
413 | STATOWNERFLAG = "-c '%U'", | ||
413 | CURLNOCERTFLAG = "", | 414 | CURLNOCERTFLAG = "", |
414 | WGETNOCERTFLAG = "", | 415 | WGETNOCERTFLAG = "", |
415 | }, | 416 | }, |
@@ -577,7 +578,8 @@ end | |||
577 | 578 | ||
578 | if cfg.platforms.bsd then | 579 | if cfg.platforms.bsd then |
579 | defaults.variables.MAKE = "gmake" | 580 | defaults.variables.MAKE = "gmake" |
580 | defaults.variables.STATFLAG = "-f '%OLp'" | 581 | defaults.variables.STATPERMFLAG = "-f '%OLp'" |
582 | defaults.variables.STATOWNERFLAG = "-f '%Su'" | ||
581 | end | 583 | end |
582 | 584 | ||
583 | if cfg.platforms.macosx then | 585 | if cfg.platforms.macosx then |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index ecf3a61b..1ad99e7f 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -178,9 +178,19 @@ function command_line.run_command(...) | |||
178 | end | 178 | end |
179 | end | 179 | end |
180 | 180 | ||
181 | if not fs.current_dir() or fs.current_dir() == "" then | 181 | if (not fs.current_dir()) or fs.current_dir() == "" then |
182 | die("Current directory does not exist. Please run LuaRocks from an existing directory.") | 182 | die("Current directory does not exist. Please run LuaRocks from an existing directory.") |
183 | end | 183 | end |
184 | |||
185 | if fs.attributes(cfg.local_cache, "owner") ~= fs.current_user() or | ||
186 | fs.attributes(dir.dir_name(cfg.local_cache), "owner") ~= fs.current_user() then | ||
187 | util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory ".. | ||
188 | "is not owned by the current user and the cache has been disabled. ".. | ||
189 | "Please check the permissions and owner of that directory. ".. | ||
190 | "If executing pip with sudo, you may want sudo's -H flag.") | ||
191 | cfg.local_cache = fs.make_temp_dir("local_cache") | ||
192 | util.schedule_function(fs.delete, cfg.local_cache) | ||
193 | end | ||
184 | 194 | ||
185 | if commands[command] then | 195 | if commands[command] then |
186 | local cmd = require(commands[command]) | 196 | local cmd = require(commands[command]) |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 90b51ce4..097f800f 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -293,7 +293,7 @@ function fs_lua.copy(src, dest, perms) | |||
293 | if destmode == "directory" then | 293 | if destmode == "directory" then |
294 | dest = dir.path(dest, dir.base_name(src)) | 294 | dest = dir.path(dest, dir.base_name(src)) |
295 | end | 295 | end |
296 | if not perms then perms = fs.get_permissions(src) end | 296 | if not perms then perms = fs.attributes(src, "permissions") end |
297 | local src_h, err = io.open(src, "rb") | 297 | local src_h, err = io.open(src, "rb") |
298 | if not src_h then return nil, err end | 298 | if not src_h then return nil, err end |
299 | local dest_h, err = io.open(dest, "w+b") | 299 | local dest_h, err = io.open(dest, "w+b") |
@@ -758,8 +758,18 @@ function fs_lua.chmod(file, mode) | |||
758 | return err == 0 | 758 | return err == 0 |
759 | end | 759 | end |
760 | 760 | ||
761 | function fs_lua.get_permissions(file) | 761 | function fs_lua.attributes(file, attrtype) |
762 | return posix.stat(file, "mode") | 762 | if attrtype == "permissions" then |
763 | return posix.stat(file, "mode") | ||
764 | elseif attrtype == "owner" then | ||
765 | return posix.getpwuid(posix.stat(file, "uid")).pw_name | ||
766 | else | ||
767 | return "" | ||
768 | end | ||
769 | end | ||
770 | |||
771 | function fs_lua.current_user() | ||
772 | return posix.getpwuid(posix.geteuid()).pw_name | ||
763 | end | 773 | end |
764 | 774 | ||
765 | --- Create a temporary directory. | 775 | --- Create a temporary directory. |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index e2bdc7b8..5c51bad5 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -132,4 +132,8 @@ function unix.tmpname() | |||
132 | return os.tmpname() | 132 | return os.tmpname() |
133 | end | 133 | end |
134 | 134 | ||
135 | function unix.current_user() | ||
136 | return os.getenv("USER") | ||
137 | end | ||
138 | |||
135 | return unix | 139 | return unix |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index d0802725..21cc8a19 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -200,8 +200,11 @@ function tools.unpack_archive(archive) | |||
200 | return true | 200 | return true |
201 | end | 201 | end |
202 | 202 | ||
203 | function tools.get_permissions(filename) | 203 | function tools.attributes(filename, attrtype) |
204 | local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) | 204 | local flag = ((attrtype == "permissions") and vars.STATPERMFLAG) |
205 | or ((attrtype == "owner") and vars.STATOWNERFLAG) | ||
206 | if not flag then return "" end | ||
207 | local pipe = io.popen(vars.STAT.." "..flag.." "..fs.Q(filename)) | ||
205 | local ret = pipe:read("*l") | 208 | local ret = pipe:read("*l") |
206 | pipe:close() | 209 | pipe:close() |
207 | return ret | 210 | return ret |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index cfc28d35..406ee8ce 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -191,7 +191,12 @@ function win32.chmod(filename, mode) | |||
191 | return true | 191 | return true |
192 | end | 192 | end |
193 | 193 | ||
194 | function win32.get_permissions(filename) | 194 | function win32.attributes(filename, attrtype) |
195 | if attrtype == "permissions" then | ||
196 | return "" -- FIXME | ||
197 | elseif attrtype == "owner" then | ||
198 | return os.getenv("USERNAME") -- FIXME popen_read('powershell -Command "& {(get-acl '..filename..').owner}"'):gsub("^[^\\]*\\", "") | ||
199 | end | ||
195 | return "" | 200 | return "" |
196 | end | 201 | end |
197 | 202 | ||
@@ -263,4 +268,8 @@ function win32.tmpname() | |||
263 | return os.getenv("TMP")..os.tmpname() | 268 | return os.getenv("TMP")..os.tmpname() |
264 | end | 269 | end |
265 | 270 | ||
271 | function win32.current_user() | ||
272 | return os.getenv("USERNAME") | ||
273 | end | ||
274 | |||
266 | return win32 | 275 | return win32 |