--- 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
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
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)
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)
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
-- @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
-- 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)
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