]> git.e2factory.org Git - e2factory.git/commitdiff
Replace shell command mktemp with a mkstemp() call.
authorTobias Ulmer <tu@emlix.com>
Tue, 12 Nov 2013 15:30:37 +0000 (16:30 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index e8c2b3c899281a56a7029de984c0ba0152c211db..bdefd4e5d830c39ab8fe5a76b47136740fb719dc 100644 (file)
@@ -1468,24 +1468,34 @@ end
 -- @return Name of the file or false on error.
 -- @return Error object on failure.
 function e2lib.mktempfile(template)
+    local rc, re, errstring, tmpfile, tmpfd, tmpfo
+
     if not template then
         template = string.format("%s/e2tmp.%d.XXXXXXXX", e2lib.globals.tmpdir,
             e2lib.getpid())
     end
-    local cmd = string.format("mktemp '%s'", template)
-    local mktemp = io.popen(cmd, "r")
-    if not mktemp then
-        return false, err.new("can't mktemp")
+
+    rc, errstring, tmpfile, tmpfd = le2lib.mkstemp(template)
+    if not rc then
+        return false, err.new("could not create temporary file: %s", errstring)
     end
-    local tmp = mktemp:read()
-    if not tmp then
-        return false, err.new("can't mktemp")
+
+    -- Currently we do not use the file descriptor, close it.
+    tmpfo, re = eio.fdopen(tmpfd, "w")
+    if not tmpfo then
+        return false, re
     end
-    mktemp:close()
+
+    rc, re = eio.fclose(tmpfo)
+    if not rc then
+        return false, re
+    end
+
     -- register tmp for removing with rmtempfiles() later on
-    table.insert(e2lib.globals.tmpfiles, tmp)
-    e2lib.logf(4, "creating temporary file: %s", tmp)
-    return tmp
+    table.insert(e2lib.globals.tmpfiles, tmpfile)
+    e2lib.logf(4, "e2lib.mktempfile: created %s", tmpfile)
+
+    return tmpfile
 end
 
 --- Delete the temporary file and remove it from the builtin list of