diff options
| author | daurnimator <quae@daurnimator.com> | 2020-10-29 05:46:41 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-28 15:46:41 -0300 |
| commit | 9d30bec0afe93a7a2284ae8adeeb03b2b36709dc (patch) | |
| tree | 8fdc5ae688b12c47538ebad0f91615a0d185830b | |
| parent | 3a356aa01db8587f7598512ca30d8a8ec8f113d1 (diff) | |
| download | luarocks-9d30bec0afe93a7a2284ae8adeeb03b2b36709dc.tar.gz luarocks-9d30bec0afe93a7a2284ae8adeeb03b2b36709dc.tar.bz2 luarocks-9d30bec0afe93a7a2284ae8adeeb03b2b36709dc.zip | |
Use table.pack so that nil varags aren't dropped (#1229)
* fs: fix verbose mode when an argument is nil
* Use table.pack in more places
| -rw-r--r-- | src/luarocks/cmd.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fs.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/tools/zip.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 5 |
5 files changed, 20 insertions, 9 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 37266b40..9077652a 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -12,6 +12,7 @@ local fs = require("luarocks.fs") | |||
| 12 | local argparse = require("luarocks.argparse") | 12 | local argparse = require("luarocks.argparse") |
| 13 | 13 | ||
| 14 | local unpack = table.unpack or unpack | 14 | local unpack = table.unpack or unpack |
| 15 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 15 | 16 | ||
| 16 | local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded") | 17 | local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded") |
| 17 | if not hc_ok then | 18 | if not hc_ok then |
| @@ -532,10 +533,10 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 532 | end | 533 | end |
| 533 | 534 | ||
| 534 | local function process_cmdline_vars(...) | 535 | local function process_cmdline_vars(...) |
| 535 | local args = {...} | 536 | local args = pack(...) |
| 536 | local cmdline_vars = {} | 537 | local cmdline_vars = {} |
| 537 | local last = #args | 538 | local last = args.n |
| 538 | for i = 1, #args do | 539 | for i = 1, args.n do |
| 539 | if args[i] == "--" then | 540 | if args[i] == "--" then |
| 540 | last = i - 1 | 541 | last = i - 1 |
| 541 | break | 542 | break |
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 54891eac..bd1a96a2 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
| @@ -58,8 +58,9 @@ do | |||
| 58 | if name ~= "init" and not fs[name] then | 58 | if name ~= "init" and not fs[name] then |
| 59 | fs[name] = function(...) | 59 | fs[name] = function(...) |
| 60 | if fs_is_verbose then | 60 | if fs_is_verbose then |
| 61 | local args = { ... } | 61 | local args = pack(...) |
| 62 | for i, arg in ipairs(args) do | 62 | for i=1, args.n do |
| 63 | local arg = args[i] | ||
| 63 | local pok, v = pcall(string.format, "%q", arg) | 64 | local pok, v = pcall(string.format, "%q", arg) |
| 64 | args[i] = pok and v or tostring(arg) | 65 | args[i] = pok and v or tostring(arg) |
| 65 | end | 66 | end |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index e431adfd..b9b36447 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -10,6 +10,8 @@ local cfg = require("luarocks.core.cfg") | |||
| 10 | local dir = require("luarocks.dir") | 10 | local dir = require("luarocks.dir") |
| 11 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
| 12 | 12 | ||
| 13 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 14 | |||
| 13 | local socket_ok, zip_ok, lfs_ok, md5_ok, posix_ok, bz2_ok, _ | 15 | local socket_ok, zip_ok, lfs_ok, md5_ok, posix_ok, bz2_ok, _ |
| 14 | local http, ftp, zip, lfs, md5, posix, bz2 | 16 | local http, ftp, zip, lfs, md5, posix, bz2 |
| 15 | 17 | ||
| @@ -54,7 +56,9 @@ end | |||
| 54 | 56 | ||
| 55 | local function quote_args(command, ...) | 57 | local function quote_args(command, ...) |
| 56 | local out = { command } | 58 | local out = { command } |
| 57 | for _, arg in ipairs({...}) do | 59 | local args = pack(...) |
| 60 | for i=1, args.n do | ||
| 61 | local arg = args[i] | ||
| 58 | assert(type(arg) == "string") | 62 | assert(type(arg) == "string") |
| 59 | out[#out+1] = fs.Q(arg) | 63 | out[#out+1] = fs.Q(arg) |
| 60 | end | 64 | end |
diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index f08162c5..fb27456d 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua | |||
| @@ -8,6 +8,8 @@ local fs = require("luarocks.fs") | |||
| 8 | local fun = require("luarocks.fun") | 8 | local fun = require("luarocks.fun") |
| 9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
| 10 | 10 | ||
| 11 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 12 | |||
| 11 | local stat_ok, stat = pcall(require, "posix.sys.stat") | 13 | local stat_ok, stat = pcall(require, "posix.sys.stat") |
| 12 | 14 | ||
| 13 | local function shr(n, m) | 15 | local function shr(n, m) |
| @@ -284,8 +286,10 @@ function zip.zip(zipfile, ...) | |||
| 284 | return nil, "error opening "..zipfile | 286 | return nil, "error opening "..zipfile |
| 285 | end | 287 | end |
| 286 | 288 | ||
| 289 | local args = pack(...) | ||
| 287 | local ok, err | 290 | local ok, err |
| 288 | for _, file in pairs({...}) do | 291 | for i=1, args.n do |
| 292 | local file = args[i] | ||
| 289 | if fs.is_dir(file) then | 293 | if fs.is_dir(file) then |
| 290 | for _, entry in pairs(fs.find(file)) do | 294 | for _, entry in pairs(fs.find(file)) do |
| 291 | local fullname = dir.path(file, entry) | 295 | local fullname = dir.path(file, entry) |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 29a8f8e4..6161a061 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -20,6 +20,7 @@ util.warning = core.warning | |||
| 20 | util.keys = core.keys | 20 | util.keys = core.keys |
| 21 | 21 | ||
| 22 | local unpack = unpack or table.unpack | 22 | local unpack = unpack or table.unpack |
| 23 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 23 | 24 | ||
| 24 | local scheduled_functions = {} | 25 | local scheduled_functions = {} |
| 25 | local debug = require("debug") | 26 | local debug = require("debug") |
| @@ -34,7 +35,7 @@ local debug = require("debug") | |||
| 34 | function util.schedule_function(f, ...) | 35 | function util.schedule_function(f, ...) |
| 35 | assert(type(f) == "function") | 36 | assert(type(f) == "function") |
| 36 | 37 | ||
| 37 | local item = { fn = f, args = {...} } | 38 | local item = { fn = f, args = pack(...) } |
| 38 | table.insert(scheduled_functions, item) | 39 | table.insert(scheduled_functions, item) |
| 39 | return item | 40 | return item |
| 40 | end | 41 | end |
| @@ -64,7 +65,7 @@ function util.run_scheduled_functions() | |||
| 64 | end | 65 | end |
| 65 | for i = #scheduled_functions, 1, -1 do | 66 | for i = #scheduled_functions, 1, -1 do |
| 66 | local item = scheduled_functions[i] | 67 | local item = scheduled_functions[i] |
| 67 | item.fn(unpack(item.args)) | 68 | item.fn(unpack(item.args, 1, item.args.n)) |
| 68 | end | 69 | end |
| 69 | end | 70 | end |
| 70 | 71 | ||
