]> git.e2factory.org Git - e2factory.git/commitdiff
Replace popen() with callcmd_capture() and require missing err module.
authorTobias Ulmer <tu@emlix.com>
Tue, 12 Nov 2013 14:04:29 +0000 (15:04 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Due to pure luck, nobody ran into a code path using err yet...

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/tools.lua

index 529b4ad62c0ec300a692fb891b9545d3655b5ef7..e0bf087a581bf205ea1c732d8b25aa0505476a24 100644 (file)
@@ -30,6 +30,7 @@
 
 local tools = {}
 local e2lib = require("e2lib")
+local err = require("err")
 local strict = require("strict")
 local buildconfig = require("buildconfig")
 
@@ -151,21 +152,33 @@ end
 --         error, if the second return value is not nil.
 -- @return Error object on failure.
 function tools.check_tool(name)
-    local tool, which, p
+    local rc, re, tool, which, p, out
     if not toollist[name] then
         return false, err.new("tool '%s' is not registered in tool list", name)
     end
 
     tool = toollist[name]
     if not tool.path then
-        which = string.format("which \"%s\"", tool.name)
-        p = io.popen(which, "r")
-        tool.path = p:read()
-        p:close()
-        if not tool.path then
-            return false
+        out = {}
+        local function capture(msg)
+            table.insert(out, msg)
+        end
+
+        which = { e2lib.shquote("which"), e2lib.shquote(tool.name) }
+        rc, re = e2lib.callcmd_capture(table.concat(which, " "), capture)
+        if not rc then
+            return false, re
+        elseif rc ~= 0 then
+            return false, err.new("tool %q not found in PATH", tool.name)
+        end
+
+        tool.path = string.sub(table.concat(out), 1, -2)
+        if not e2lib.exists(tool.path, true) then
+            return false,
+                err.new("tool %q not found at %q", tool.name, tool.path)
         end
     end
+
     return true
 end