diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2015-12-05 15:07:21 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-12-05 15:07:21 -0200 |
| commit | bf12327a64400884b2be50c88cc8b223db57260c (patch) | |
| tree | b0c60ffc3e25e36748f42488fc8136e82d45b21e | |
| parent | 0b4741a2622a08c6ec6baa099cd1bd3de5c8139b (diff) | |
| download | luarocks-bf12327a64400884b2be50c88cc8b223db57260c.tar.gz luarocks-bf12327a64400884b2be50c88cc8b223db57260c.tar.bz2 luarocks-bf12327a64400884b2be50c88cc8b223db57260c.zip | |
Improve writability checks.
LuaRocks does `mkdir -p` (or equivalent), so we can check
for the entire chain of parents for a writable directory.
Closes #449.
| -rw-r--r-- | src/luarocks/fs/lua.lua | 17 | ||||
| -rw-r--r-- | src/luarocks/fs/unix.lua | 8 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 18 |
3 files changed, 33 insertions, 10 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 18e6b01a..a444f014 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -833,10 +833,19 @@ function fs_lua.check_command_permissions(flags) | |||
| 833 | break | 833 | break |
| 834 | end | 834 | end |
| 835 | end | 835 | end |
| 836 | local root_parent = dir.dir_name(root_dir) | 836 | if ok and not fs.exists(root_dir) then |
| 837 | if ok and not fs.exists(root_dir) and not fs.is_writable(root_parent) then | 837 | local root = fs.root_of(root_dir) |
| 838 | ok = false | 838 | local parent = root_dir |
| 839 | err = root_dir.." does not exist and your user does not have write permissions in " .. root_parent | 839 | repeat |
| 840 | parent = dir.dir_name(parent) | ||
| 841 | if parent == "" then | ||
| 842 | parent = root | ||
| 843 | end | ||
| 844 | until parent == root or fs.exists(parent) | ||
| 845 | if not fs.is_writable(parent) then | ||
| 846 | ok = false | ||
| 847 | err = root_dir.." does not exist and your user does not have write permissions in " .. parent | ||
| 848 | end | ||
| 840 | end | 849 | end |
| 841 | if ok then | 850 | if ok then |
| 842 | return true | 851 | return true |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 6ad5a678..8eb3386a 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
| @@ -36,6 +36,14 @@ function unix.absolute_name(pathname, relative_to) | |||
| 36 | end | 36 | end |
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | --- Return the root directory for the given path. | ||
| 40 | -- In Unix, root is always "/". | ||
| 41 | -- @param pathname string: pathname to use. | ||
| 42 | -- @return string: The root of the given pathname. | ||
| 43 | function unix.root_of(_) | ||
| 44 | return "/" | ||
| 45 | end | ||
| 46 | |||
| 39 | --- Create a wrapper to make a script executable from the command-line. | 47 | --- Create a wrapper to make a script executable from the command-line. |
| 40 | -- @param file string: Pathname of script to be made executable. | 48 | -- @param file string: Pathname of script to be made executable. |
| 41 | -- @param dest string: Directory where to put the wrapper. | 49 | -- @param dest string: Directory where to put the wrapper. |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 32766e53..0c8cc9e9 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -18,7 +18,6 @@ local _popen, _execute = io.popen, os.execute | |||
| 18 | io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end | 18 | io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end |
| 19 | os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end | 19 | os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end |
| 20 | 20 | ||
| 21 | |||
| 22 | --- Annotate command string for quiet execution. | 21 | --- Annotate command string for quiet execution. |
| 23 | -- @param cmd string: A command-line string. | 22 | -- @param cmd string: A command-line string. |
| 24 | -- @return string: The command-line, with silencing annotation. | 23 | -- @return string: The command-line, with silencing annotation. |
| @@ -26,6 +25,7 @@ function win32.quiet(cmd) | |||
| 26 | return cmd.." 2> NUL 1> NUL" | 25 | return cmd.." 2> NUL 1> NUL" |
| 27 | end | 26 | end |
| 28 | 27 | ||
| 28 | local drive_letter = "[%.a-zA-Z]?:?[\\/]" | ||
| 29 | 29 | ||
| 30 | local win_escape_chars = { | 30 | local win_escape_chars = { |
| 31 | ["%"] = "%%", | 31 | ["%"] = "%%", |
| @@ -47,7 +47,7 @@ end | |||
| 47 | function win32.Q(arg) | 47 | function win32.Q(arg) |
| 48 | assert(type(arg) == "string") | 48 | assert(type(arg) == "string") |
| 49 | -- Quote DIR for Windows | 49 | -- Quote DIR for Windows |
| 50 | if arg:match("^[%.a-zA-Z]?:?[\\/]") then | 50 | if arg:match("^"..drive_letter) then |
| 51 | arg = arg:gsub("/", "\\") | 51 | arg = arg:gsub("/", "\\") |
| 52 | end | 52 | end |
| 53 | if arg == "\\" then | 53 | if arg == "\\" then |
| @@ -68,7 +68,7 @@ end | |||
| 68 | function win32.Qb(arg) | 68 | function win32.Qb(arg) |
| 69 | assert(type(arg) == "string") | 69 | assert(type(arg) == "string") |
| 70 | -- Quote DIR for Windows | 70 | -- Quote DIR for Windows |
| 71 | if arg:match("^[%.a-zA-Z]?:?[\\/]") then | 71 | if arg:match("^"..drive_letter) then |
| 72 | arg = arg:gsub("/", "\\") | 72 | arg = arg:gsub("/", "\\") |
| 73 | end | 73 | end |
| 74 | if arg == "\\" then | 74 | if arg == "\\" then |
| @@ -92,15 +92,21 @@ function win32.absolute_name(pathname, relative_to) | |||
| 92 | assert(type(relative_to) == "string" or not relative_to) | 92 | assert(type(relative_to) == "string" or not relative_to) |
| 93 | 93 | ||
| 94 | relative_to = relative_to or fs.current_dir() | 94 | relative_to = relative_to or fs.current_dir() |
| 95 | -- FIXME I'm not sure this first \\ should be there at all. | 95 | if pathname:match("^"..drive_letter) then |
| 96 | -- What are the Windows rules for drive letters? | ||
| 97 | if pathname:match("^[\\.a-zA-Z]?:?[\\/]") then | ||
| 98 | return pathname | 96 | return pathname |
| 99 | else | 97 | else |
| 100 | return relative_to .. "/" .. pathname | 98 | return relative_to .. "/" .. pathname |
| 101 | end | 99 | end |
| 102 | end | 100 | end |
| 103 | 101 | ||
| 102 | --- Return the root directory for the given path. | ||
| 103 | -- For example, for "c:\hello", returns "c:\" | ||
| 104 | -- @param pathname string: pathname to use. | ||
| 105 | -- @return string: The root of the given pathname. | ||
| 106 | function win32.root_of(pathname) | ||
| 107 | return (fs.absolute_name(pathname):match("^("..drive_letter..")")) | ||
| 108 | end | ||
| 109 | |||
| 104 | --- Create a wrapper to make a script executable from the command-line. | 110 | --- Create a wrapper to make a script executable from the command-line. |
| 105 | -- @param file string: Pathname of script to be made executable. | 111 | -- @param file string: Pathname of script to be made executable. |
| 106 | -- @param dest string: Directory where to put the wrapper. | 112 | -- @param dest string: Directory where to put the wrapper. |
