]> git.e2factory.org Git - e2factory.git/commitdiff
Add error handling to e2lib.mktempfile()
authorTobias Ulmer <tu@emlix.com>
Fri, 26 Apr 2013 14:46:01 +0000 (16:46 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 13:58:55 +0000 (14:58 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
generic/generic_git.lua
local/e2-new-source.lua
local/e2tool.lua

index 5b8054012812ed705911a42b233232f6727117ff..5f1ab063d87170b465a24ae2e334dbb8ddcf7392 100644 (file)
@@ -1376,22 +1376,22 @@ end
 --- Create a temporary file.
 -- The template string is passed to the mktemp tool, which replaces
 -- trailing X characters by some random string to create a unique name.
--- This function always succeeds (or aborts immediately).
 -- @param template string: template name (optional)
--- @return string: name of the file
+-- @return Name of the file or false on error.
+-- @return Error object on failure.
 function e2lib.mktempfile(template)
     if not template then
         template = string.format("%s/e2tmp.%d.XXXXXXXX", e2lib.globals.tmpdir,
-        e2util.getpid())
+            e2util.getpid())
     end
     local cmd = string.format("mktemp '%s'", template)
     local mktemp = io.popen(cmd, "r")
     if not mktemp then
-        e2lib.abort("can't mktemp")
+        return false, err.new("can't mktemp")
     end
     local tmp = mktemp:read()
     if not tmp then
-        e2lib.abort("can't mktemp")
+        return false, err.new("can't mktemp")
     end
     mktemp:close()
     -- register tmp for removing with rmtempfiles() later on
index e45fb0c214125b3db01762f0691b5de56a4c9e0b..1b7fd7256cec43023d8ac1257013ee7e059a677a 100644 (file)
@@ -129,7 +129,12 @@ end
 function generic_git.git_rev_list1(gitdir, ref)
     local e = err.new("git rev-list failed")
     local rc, re
-    local tmpfile = e2lib.mktempfile()
+
+    local tmpfile, re = e2lib.mktempfile()
+    if not tmpfile then
+        return false, e:cat(re)
+    end
+
     local args = string.format("--max-count=1 '%s' -- >'%s'", ref, tmpfile)
     rc, re = e2lib.git(gitdir, "rev-list", args)
     if not rc then
@@ -359,7 +364,12 @@ end
 function generic_git.git_config(gitdir, query)
     local rc, re
     local e = err.new("running git config")
-    local tmpfile = e2lib.mktempfile()
+
+    local tmpfile, re = e2lib.mktempfile()
+    if not tmpfile then
+        return false, e:cat(re)
+    end
+
     local cmd = string.format("GIT_DIR=%s git config %s > %s",
     e2lib.shquote(gitdir), e2lib.shquote(query), e2lib.shquote(tmpfile))
     local rc, re = e2lib.callcmd_log(cmd)
@@ -464,7 +474,12 @@ function generic_git.verify_clean_repository(gitwc)
     gitwc = gitwc or "."
     local e = err.new("verifying that repository is clean")
     local rc, re
-    local tmp = e2lib.mktempfile()
+
+    local tmp, re = e2lib.mktempfile()
+    if not tmp then
+        return false, e:cat(re)
+    end
+
     rc, re = e2lib.chdir(gitwc)
     if not rc then
         return nil, e:cat(re)
@@ -534,7 +549,12 @@ function generic_git.verify_head_match_tag(gitwc, verify_tag)
     gitwc = gitwc or "."
     local e = err.new("verifying that HEAD matches 'refs/tags/%s'", verify_tag)
     local rc, re
-    local tmp = e2lib.mktempfile()
+
+    local tmp, re = e2lib.mktempfile()
+    if not tmp then
+        return false, e:cat(re)
+    end
+
     local args = string.format("--tags --match '%s' >%s", verify_tag, tmp)
     rc, re = e2lib.chdir(gitwc)
     if not rc then
index 8d4619577e07f898a5acdf29fda96e60c3361c99..0c4fcda0cef5d01a79ab86449b2375a91e62e479 100644 (file)
@@ -45,14 +45,19 @@ local url = require("url")
 -- @return temporary filename or false.
 -- @return an error object on failure.
 local function download(f)
+    local rc, re
     local path = e2lib.dirname(f)
     local fn = e2lib.basename(f)
 
-    local tfile = e2lib.mktempfile()
+    local tfile, re = e2lib.mktempfile()
+    if not tfile then
+        return false, re
+    end
+
     local tpath = e2lib.dirname(tfile)
     local tfn = e2lib.basename(tfile)
 
-    local rc, re = transport.fetch_file(path, fn, tpath, tfn)
+    rc, re = transport.fetch_file(path, fn, tpath, tfn)
     if not rc then
         return rc, re
     end
@@ -120,7 +125,10 @@ local function new_files_source(c, server, location, source_file, checksum_file,
 
     -- check for file with identical name on the server
     local tmpfile = {}
-    tmpfile.file = e2lib.mktempfile()
+    tmpfile.file, re = e2lib.mktempfile()
+    if not tmpfile.file then
+        return false, e:cat(re)
+    end
     tmpfile.base = e2lib.basename(tmpfile.file)
     tmpfile.dir = e2lib.dirname(tmpfile.file)
 
index f8346f7f51b895df7a0b3ce3d4aa14e9c9f81240..58024e7a4934177724cf19d989ceabe92bdd4b7d 100644 (file)
@@ -2029,7 +2029,11 @@ local function verify_remote_fileid(info, file, fileid)
             return false, e:cat(re)
         end
 
-        local tmpfile = e2lib.mktempfile()
+        local tmpfile, re = e2lib.mktempfile()
+        if not tmpfile then
+            return false, e:cat(re)
+        end
+
         rc, re = transport.fetch_file(ce.remote_url, file.location,
             e2lib.dirname(tmpfile), e2lib.basename(tmpfile))
         if not rc then