diff options
author | Hisham <hisham@gobolinux.org> | 2017-01-06 17:30:38 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2017-01-06 17:30:38 -0200 |
commit | e6b161fabc5a3122bc11162e3f42df2c802f3673 (patch) | |
tree | c0fad2f5af143b85e5d9c2433b4b9439094f5715 /src | |
parent | 3df4bd569e44a7e4a6a0d5d3b758c767d9b562c4 (diff) | |
download | luarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.tar.gz luarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.tar.bz2 luarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.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/command_line.lua | 12 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 6 | ||||
-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/command_line.lua b/src/luarocks/command_line.lua index 96891b75..3f17b18a 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/core/cfg.lua b/src/luarocks/core/cfg.lua index de8b9281..250f503e 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -411,7 +411,8 @@ local defaults = { | |||
411 | SEVENZ = "7z", | 411 | SEVENZ = "7z", |
412 | 412 | ||
413 | RSYNCFLAGS = "--exclude=.git -Oavz", | 413 | RSYNCFLAGS = "--exclude=.git -Oavz", |
414 | STATFLAG = "-c '%a'", | 414 | STATPERMFLAG = "-c '%a'", |
415 | STATOWNERFLAG = "-c '%U'", | ||
415 | CURLNOCERTFLAG = "", | 416 | CURLNOCERTFLAG = "", |
416 | WGETNOCERTFLAG = "", | 417 | WGETNOCERTFLAG = "", |
417 | }, | 418 | }, |
@@ -586,7 +587,8 @@ end | |||
586 | 587 | ||
587 | if cfg.platforms.bsd then | 588 | if cfg.platforms.bsd then |
588 | defaults.variables.MAKE = "gmake" | 589 | defaults.variables.MAKE = "gmake" |
589 | defaults.variables.STATFLAG = "-f '%OLp'" | 590 | defaults.variables.STATPERMFLAG = "-f '%OLp'" |
591 | defaults.variables.STATOWNERFLAG = "-f '%Su'" | ||
590 | end | 592 | end |
591 | 593 | ||
592 | if cfg.platforms.macosx then | 594 | if cfg.platforms.macosx then |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 84037b0a..a14303e1 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 aca64ac0..89e3ec73 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 d9dc009f..e1b28b19 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 789913a7..e2b37778 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 |