aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-09-15 21:07:42 -0700
committerHisham Muhammad <hisham@gobolinux.org>2018-09-16 23:39:10 -0700
commit710e3e446804957b935cd9fda5aa2f2c2a55a4f4 (patch)
tree1e5a386f1002111a8f42af6513cc2f09f9eea10c
parent0edb339f984c82accedbc1bbd799bfe31029c52e (diff)
downloadluarocks-710e3e446804957b935cd9fda5aa2f2c2a55a4f4.tar.gz
luarocks-710e3e446804957b935cd9fda5aa2f2c2a55a4f4.tar.bz2
luarocks-710e3e446804957b935cd9fda5aa2f2c2a55a4f4.zip
core.util: be more resilient when reading command outputs
When luarocks.loader runs from within another process, we may end up getting an Interrupted signal when reading from a pipe, which is not handled by Lua.
-rw-r--r--src/luarocks/core/util.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua
index 5f5c0fe1..8789851c 100644
--- a/src/luarocks/core/util.lua
+++ b/src/luarocks/core/util.lua
@@ -12,10 +12,17 @@ local require = nil
12-- May be used to read more, passing, for instance, "*a". 12-- May be used to read more, passing, for instance, "*a".
13-- @return string: the output of the program. 13-- @return string: the output of the program.
14function util.popen_read(cmd, spec) 14function util.popen_read(cmd, spec)
15 local fd = io.popen(cmd) 15 local tmpfile = os.tmpname()
16 os.execute(cmd .. " > " .. tmpfile)
17 local fd = io.open(tmpfile, "rb")
18 if not fd then
19 os.remove(tmpfile)
20 return ""
21 end
16 local out = fd:read(spec or "*l") 22 local out = fd:read(spec or "*l")
17 fd:close() 23 fd:close()
18 return out 24 os.remove(tmpfile)
25 return out or ""
19end 26end
20 27
21--- Create a new shallow copy of a table: a new table with 28--- Create a new shallow copy of a table: a new table with