diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-14 22:01:53 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-03-15 19:45:26 -0300 |
| commit | e4315e0511ecce37d7848dc4ffe11b59b778256a (patch) | |
| tree | 39c2c9ae3d79cc59cf6cb50e0857d114b5b6f426 | |
| parent | 6d7723a48093eb49b17fd1e5eb3653b9c20461b7 (diff) | |
| download | luarocks-e4315e0511ecce37d7848dc4ffe11b59b778256a.tar.gz luarocks-e4315e0511ecce37d7848dc4ffe11b59b778256a.tar.bz2 luarocks-e4315e0511ecce37d7848dc4ffe11b59b778256a.zip | |
core.cfg: produce quoted values in tool variables for Windows
Alternative solution to the problem described in #968. We can't
use #968 because on Unix sometimes people set the value of those
variables so they include arguments (even LuaRocks does it
by default, setting `UNZIP="unzip -n"`).
Now that the variables are quoted, we stop auto-quoting them
in `luarocks.fs`. I expect this change to have to practical
impact on Unix, where paths with spaces are uncommon (those can
use explicit quotes in their values).
| -rw-r--r-- | src/luarocks/core/cfg.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/fs/tools.lua | 10 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 28 | ||||
| -rw-r--r-- | src/luarocks/upload/api.lua | 2 |
4 files changed, 21 insertions, 21 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 75075792..5cfa10c3 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -720,7 +720,7 @@ function cfg.init(lua_data, project_dir, warning) | |||
| 720 | if platforms.windows and hardcoded.WIN_TOOLS then | 720 | if platforms.windows and hardcoded.WIN_TOOLS then |
| 721 | local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "TEST", "WGET", "MKDIR" } | 721 | local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "TEST", "WGET", "MKDIR" } |
| 722 | for _, tool in ipairs(tools) do | 722 | for _, tool in ipairs(tools) do |
| 723 | defaults.variables[tool] = hardcoded.WIN_TOOLS .. "/" .. defaults.variables[tool] .. ".exe" | 723 | defaults.variables[tool] = '"' .. hardcoded.WIN_TOOLS .. "/" .. defaults.variables[tool] .. '.exe"' |
| 724 | end | 724 | end |
| 725 | else | 725 | else |
| 726 | defaults.fs_use_modules = true | 726 | defaults.fs_use_modules = true |
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index 691d670e..52915781 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua | |||
| @@ -39,7 +39,7 @@ do | |||
| 39 | if not tool then | 39 | if not tool then |
| 40 | return nil | 40 | return nil |
| 41 | end | 41 | end |
| 42 | return tool.name, fs.Q(vars[tool.var]) .. (tool.cmdarg and " "..tool.cmdarg or "") | 42 | return tool.name, vars[tool.var] .. (tool.cmdarg and " "..tool.cmdarg or "") |
| 43 | end | 43 | end |
| 44 | end | 44 | end |
| 45 | 45 | ||
| @@ -51,7 +51,7 @@ do | |||
| 51 | function tools.current_dir() | 51 | function tools.current_dir() |
| 52 | local current = cache_pwd | 52 | local current = cache_pwd |
| 53 | if not current then | 53 | if not current then |
| 54 | local pipe = io.popen(fs.quiet_stderr(fs.Q(vars.PWD))) | 54 | local pipe = io.popen(fs.quiet_stderr(vars.PWD)) |
| 55 | current = pipe:read("*l") | 55 | current = pipe:read("*l") |
| 56 | pipe:close() | 56 | pipe:close() |
| 57 | cache_pwd = current | 57 | cache_pwd = current |
| @@ -118,7 +118,7 @@ end | |||
| 118 | -- @param at string: directory to list | 118 | -- @param at string: directory to list |
| 119 | -- @return nil | 119 | -- @return nil |
| 120 | function tools.dir_iterator(at) | 120 | function tools.dir_iterator(at) |
| 121 | local pipe = io.popen(fs.command_at(at, fs.Q(vars.LS), true)) | 121 | local pipe = io.popen(fs.command_at(at, vars.LS, true)) |
| 122 | for file in pipe:lines() do | 122 | for file in pipe:lines() do |
| 123 | if file ~= "." and file ~= ".." then | 123 | if file ~= "." and file ~= ".." then |
| 124 | coroutine.yield(file) | 124 | coroutine.yield(file) |
| @@ -147,7 +147,7 @@ function tools.use_downloader(url, filename, cache) | |||
| 147 | 147 | ||
| 148 | local ok | 148 | local ok |
| 149 | if downloader == "wget" then | 149 | if downloader == "wget" then |
| 150 | local wget_cmd = fs.Q(vars.WGET).." "..vars.WGETNOCERTFLAG.." --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " | 150 | local wget_cmd = vars.WGET.." "..vars.WGETNOCERTFLAG.." --no-cache --user-agent=\""..cfg.user_agent.." via wget\" --quiet " |
| 151 | if cfg.connection_timeout and cfg.connection_timeout > 0 then | 151 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
| 152 | wget_cmd = wget_cmd .. "--timeout="..tostring(cfg.connection_timeout).." --tries=1 " | 152 | wget_cmd = wget_cmd .. "--timeout="..tostring(cfg.connection_timeout).." --tries=1 " |
| 153 | end | 153 | end |
| @@ -163,7 +163,7 @@ function tools.use_downloader(url, filename, cache) | |||
| 163 | ok = fs.execute_quiet(wget_cmd, url) | 163 | ok = fs.execute_quiet(wget_cmd, url) |
| 164 | end | 164 | end |
| 165 | elseif downloader == "curl" then | 165 | elseif downloader == "curl" then |
| 166 | local curl_cmd = fs.Q(vars.CURL).." "..vars.CURLNOCERTFLAG.." -f -L --user-agent \""..cfg.user_agent.." via curl\" " | 166 | local curl_cmd = vars.CURL.." "..vars.CURLNOCERTFLAG.." -f -L --user-agent \""..cfg.user_agent.." via curl\" " |
| 167 | if cfg.connection_timeout and cfg.connection_timeout > 0 then | 167 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
| 168 | curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " | 168 | curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " |
| 169 | end | 169 | end |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 0fd73205..77e962eb 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -36,7 +36,7 @@ end | |||
| 36 | function tools.make_dir(directory) | 36 | function tools.make_dir(directory) |
| 37 | assert(directory) | 37 | assert(directory) |
| 38 | directory = dir.normalize(directory) | 38 | directory = dir.normalize(directory) |
| 39 | fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) | 39 | fs.execute_quiet(vars.MKDIR.." -p ", directory) |
| 40 | if not fs.is_dir(directory) then | 40 | if not fs.is_dir(directory) then |
| 41 | return false, "failed making directory "..directory | 41 | return false, "failed making directory "..directory |
| 42 | end | 42 | end |
| @@ -49,7 +49,7 @@ end | |||
| 49 | -- @param directory string: pathname of directory to remove. | 49 | -- @param directory string: pathname of directory to remove. |
| 50 | function tools.remove_dir_if_empty(directory) | 50 | function tools.remove_dir_if_empty(directory) |
| 51 | assert(directory) | 51 | assert(directory) |
| 52 | fs.execute_quiet(fs.Q(vars.RMDIR), directory) | 52 | fs.execute_quiet(vars.RMDIR, directory) |
| 53 | end | 53 | end |
| 54 | 54 | ||
| 55 | --- Remove a directory if it is empty. | 55 | --- Remove a directory if it is empty. |
| @@ -58,7 +58,7 @@ end | |||
| 58 | -- @param directory string: pathname of directory to remove. | 58 | -- @param directory string: pathname of directory to remove. |
| 59 | function tools.remove_dir_tree_if_empty(directory) | 59 | function tools.remove_dir_tree_if_empty(directory) |
| 60 | assert(directory) | 60 | assert(directory) |
| 61 | fs.execute_quiet(fs.Q(vars.RMDIR), directory) | 61 | fs.execute_quiet(vars.RMDIR, directory) |
| 62 | end | 62 | end |
| 63 | 63 | ||
| 64 | --- Copy a file. | 64 | --- Copy a file. |
| @@ -69,7 +69,7 @@ end | |||
| 69 | function tools.copy(src, dest) | 69 | function tools.copy(src, dest) |
| 70 | assert(src and dest) | 70 | assert(src and dest) |
| 71 | if dest:match("[/\\]$") then dest = dest:sub(1, -2) end | 71 | if dest:match("[/\\]$") then dest = dest:sub(1, -2) end |
| 72 | local ok = fs.execute(fs.Q(vars.CP), src, dest) | 72 | local ok = fs.execute(vars.CP, src, dest) |
| 73 | if ok then | 73 | if ok then |
| 74 | return true | 74 | return true |
| 75 | else | 75 | else |
| @@ -87,7 +87,7 @@ function tools.copy_contents(src, dest) | |||
| 87 | if not fs.is_dir(src) then | 87 | if not fs.is_dir(src) then |
| 88 | return false, src .. " is not a directory" | 88 | return false, src .. " is not a directory" |
| 89 | end | 89 | end |
| 90 | if fs.make_dir(dest) and fs.execute_quiet(fs.Q(vars.CP), "-dR", src.."\\*.*", dest) then | 90 | if fs.make_dir(dest) and fs.execute_quiet(vars.CP, "-dR", src.."\\*.*", dest) then |
| 91 | return true | 91 | return true |
| 92 | else | 92 | else |
| 93 | return false, "Failed copying "..src.." to "..dest | 93 | return false, "Failed copying "..src.." to "..dest |
| @@ -118,7 +118,7 @@ function tools.find(at) | |||
| 118 | return {} | 118 | return {} |
| 119 | end | 119 | end |
| 120 | local result = {} | 120 | local result = {} |
| 121 | local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)), true)) | 121 | local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(vars.FIND), true)) |
| 122 | for file in pipe:lines() do | 122 | for file in pipe:lines() do |
| 123 | -- Windows find is a bit different | 123 | -- Windows find is a bit different |
| 124 | local first_two = file:sub(1,2) | 124 | local first_two = file:sub(1,2) |
| @@ -137,7 +137,7 @@ end | |||
| 137 | -- additional arguments. | 137 | -- additional arguments. |
| 138 | -- @return boolean: true on success, nil and error message on failure. | 138 | -- @return boolean: true on success, nil and error message on failure. |
| 139 | function tools.zip(zipfile, ...) | 139 | function tools.zip(zipfile, ...) |
| 140 | if fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) then | 140 | if fs.execute_quiet(vars.SEVENZ.." -aoa a -tzip", zipfile, ...) then |
| 141 | return true | 141 | return true |
| 142 | else | 142 | else |
| 143 | return nil, "failed compressing " .. zipfile | 143 | return nil, "failed compressing " .. zipfile |
| @@ -149,7 +149,7 @@ end | |||
| 149 | -- @return boolean: true on success, nil and error message on failure. | 149 | -- @return boolean: true on success, nil and error message on failure. |
| 150 | function tools.unzip(zipfile) | 150 | function tools.unzip(zipfile) |
| 151 | assert(zipfile) | 151 | assert(zipfile) |
| 152 | if fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) then | 152 | if fs.execute_quiet(vars.SEVENZ.." -aoa x", zipfile) then |
| 153 | return true | 153 | return true |
| 154 | else | 154 | else |
| 155 | return nil, "failed extracting " .. zipfile | 155 | return nil, "failed extracting " .. zipfile |
| @@ -165,7 +165,7 @@ local function sevenz(default_ext, infile, outfile) | |||
| 165 | 165 | ||
| 166 | infile = fs.absolute_name(infile) | 166 | infile = fs.absolute_name(infile) |
| 167 | 167 | ||
| 168 | local cmdline = fs.Q(vars.SEVENZ).." -aoa -t* -o"..fs.Q(outdir).." x "..fs.Q(infile) | 168 | local cmdline = vars.SEVENZ.." -aoa -t* -o"..fs.Q(outdir).." x "..fs.Q(infile) |
| 169 | local ok, err = fs.execute_quiet(cmdline) | 169 | local ok, err = fs.execute_quiet(cmdline) |
| 170 | if not ok then | 170 | if not ok then |
| 171 | return nil, "failed extracting " .. infile | 171 | return nil, "failed extracting " .. infile |
| @@ -214,7 +214,7 @@ end | |||
| 214 | -- @return boolean: true if it is a regular file, false otherwise. | 214 | -- @return boolean: true if it is a regular file, false otherwise. |
| 215 | function tools.is_file(file) | 215 | function tools.is_file(file) |
| 216 | assert(file) | 216 | assert(file) |
| 217 | return fs.execute(fs.Q(vars.TEST).." -f", file) | 217 | return fs.execute(vars.TEST.." -f", file) |
| 218 | end | 218 | end |
| 219 | 219 | ||
| 220 | --- Helper function for fs.set_permissions | 220 | --- Helper function for fs.set_permissions |
| @@ -255,13 +255,13 @@ function tools.set_permissions(filename, mode, scope) | |||
| 255 | return false, "Could not take ownership of the given file" | 255 | return false, "Could not take ownership of the given file" |
| 256 | end | 256 | end |
| 257 | -- Grant the current user the proper rights | 257 | -- Grant the current user the proper rights |
| 258 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r %USERNAME%:" .. perms) | 258 | ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r %USERNAME%:" .. perms) |
| 259 | if not ok then | 259 | if not ok then |
| 260 | return false, "Failed setting permission " .. mode .. " for " .. scope | 260 | return false, "Failed setting permission " .. mode .. " for " .. scope |
| 261 | end | 261 | end |
| 262 | -- Finally, remove all the other users from the ACL in order to deny them access to the file | 262 | -- Finally, remove all the other users from the ACL in order to deny them access to the file |
| 263 | for _, user in pairs(get_system_users()) do | 263 | for _, user in pairs(get_system_users()) do |
| 264 | local ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /remove " .. fs.Q(user)) | 264 | local ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /remove " .. fs.Q(user)) |
| 265 | if not ok then | 265 | if not ok then |
| 266 | return false, "Failed setting permission " .. mode .. " for " .. scope | 266 | return false, "Failed setting permission " .. mode .. " for " .. scope |
| 267 | end | 267 | end |
| @@ -278,12 +278,12 @@ function tools.set_permissions(filename, mode, scope) | |||
| 278 | 278 | ||
| 279 | local ok | 279 | local ok |
| 280 | -- Grant permissions available to all users | 280 | -- Grant permissions available to all users |
| 281 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r *S-1-1-0:" .. others_perms) | 281 | ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r *S-1-1-0:" .. others_perms) |
| 282 | if not ok then | 282 | if not ok then |
| 283 | return false, "Failed setting permission " .. mode .. " for " .. scope | 283 | return false, "Failed setting permission " .. mode .. " for " .. scope |
| 284 | end | 284 | end |
| 285 | -- Grant permissions available only to the current user | 285 | -- Grant permissions available only to the current user |
| 286 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant %USERNAME%:" .. my_perms) | 286 | ok = fs.execute_quiet(vars.ICACLS .. " " .. fs.Q(filename) .. " /inheritance:d /grant %USERNAME%:" .. my_perms) |
| 287 | if not ok then | 287 | if not ok then |
| 288 | return false, "Failed setting permission " .. mode .. " for " .. scope | 288 | return false, "Failed setting permission " .. mode .. " for " .. scope |
| 289 | end | 289 | end |
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index bf83faf6..dd0f1309 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua | |||
| @@ -140,7 +140,7 @@ function Api:request(url, params, post_params) | |||
| 140 | local tmpfile = fs.tmpname() | 140 | local tmpfile = fs.tmpname() |
| 141 | if post_params then | 141 | if post_params then |
| 142 | method = "POST" | 142 | method = "POST" |
| 143 | local curl_cmd = fs.Q(vars.CURL).." -f -k -L --silent --user-agent \""..cfg.user_agent.." via curl\" " | 143 | local curl_cmd = vars.CURL.." -f -k -L --silent --user-agent \""..cfg.user_agent.." via curl\" " |
| 144 | for k,v in pairs(post_params) do | 144 | for k,v in pairs(post_params) do |
| 145 | local var = v | 145 | local var = v |
| 146 | if type(v) == "table" then | 146 | if type(v) == "table" then |
