]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: support e2.conf config.site.tmpdir setting and E2_TMPDIR
authorTobias Ulmer <tu@emlix.com>
Tue, 19 Mar 2019 16:38:42 +0000 (17:38 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 19 Mar 2019 16:39:33 +0000 (17:39 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
doc/man/e2.conf.5.in
doc/man/e2factory.1.in
generic/e2lib.lua

index 70d4d1d5476cc3c689dbedf32e3f462196807e3b..81763b6ab6ab726c792e38590d54215e09c5a9ff 100644 (file)
@@ -64,6 +64,7 @@ config {
     e2_base = "<string>",
     e2_branch = "<string>",
     e2_tag = "<string>",
+    tmpdir = "<string>",
     default_extensions = {
        {
                name = "<string>",
@@ -143,6 +144,12 @@ Type: String
 .br
 Name of the git tag of the e2factory version to use, when using \fBe2-create-project\fR(1).
 
+.TP
+.BR tmpdir
+Type: String
+.br
+Temporary directory to use when no environment variable is set. Optional.
+
 .TP
 .BR default_extensions
 Type: Table
index 17368a55f5e62d4f9109078d5dfe314798dbb6d5..72ec49863d3fe566f57b073d61aa7a5914c516b8 100644 (file)
@@ -193,6 +193,9 @@ Name of the user.
 .BR E2TMPDIR
 Temporary directory to be used. Overwrites \fBTMPDIR\fR.
 .TP
+.BR E2_TMPDIR
+Alias for \fBE2TMPDIR.
+.TP
 .BR E2_CONFIG
 Path to the config file.
 .TP
index d7ab5ad9618fbff7f66098ad26626671e92faaf2..8ae33751b426eea4211abcdfed65de85666fc3f0 100644 (file)
@@ -525,6 +525,37 @@ function e2lib.interrupt_hook()
     children_send_sigint()
 end
 
+--- Return highest priority tmpdir.
+-- @param config Config table, optional
+-- @return tmpdir path, may not exist
+local function select_tmpdir(config)
+    assert(config == nil or assertIsTable(config))
+    local t
+
+    -- In order of decreasing priority
+    if not t then
+        t = e2lib.globals.osenv["E2TMPDIR"]
+    end
+    if not t then
+        t = e2lib.globals.osenv["E2_TMPDIR"]
+    end
+    if not t then
+        if config and config.site.tmpdir then
+            t = config.site.tmpdir
+        end
+    end
+    if not t then
+        t = e2lib.globals.osenv["TMPDIR"]
+    end
+    if not t then
+        t = "/tmp"
+    end
+
+    assertIsString(t)
+    e2lib.logf(3, "selecting %q as temporary directory", t)
+    return t
+end
+
 --- Make sure the environment variables inside the globals table are
 -- initialized properly, set up output channels etc. Must be called before
 -- anything else.
@@ -559,6 +590,7 @@ function e2lib.init()
         { name = "E2_CONFIG", required = false },
         { name = "TMPDIR", required = false, default = "/tmp" },
         { name = "E2TMPDIR", required = false },
+        { name = "E2_TMPDIR", required = false },
         { name = "COLUMNS", required = false, default = "72" },
         { name = "E2_SSH", required = false },
     }
@@ -574,10 +606,11 @@ function e2lib.init()
         e2lib.globals.osenv[var.name] = var.val
     end
 
-    if e2lib.globals.osenv["E2TMPDIR"] then
-        e2lib.globals.tmpdir = e2lib.globals.osenv["E2TMPDIR"]
-    else
-        e2lib.globals.tmpdir = e2lib.globals.osenv["TMPDIR"]
+    -- init tmpdir early so it can be used during option parsing
+    e2lib.globals.tmpdir = select_tmpdir(nil)
+    if not e2lib.isdir(e2lib.globals.tmpdir) then
+        return false, err.new("temporary directory %q does not exists, "..
+            "please create it", e2lib.globals.tmpdir)
     end
 
     e2lib.globals.lock = lock.new()
@@ -602,6 +635,13 @@ function e2lib.init2()
         return false, re
     end
 
+    -- tmpdir might have changed after loading config
+    e2lib.globals.tmpdir = select_tmpdir(config)
+    if not e2lib.isdir(e2lib.globals.tmpdir) then
+        return false, e:cat("temporary directory %q does not exists, "..
+            "please create it", e2lib.globals.tmpdir)
+    end
+
     -- honour tool customizations from the config file
     if config.tools then
         for k,v in pairs(config.tools) do
@@ -1092,9 +1132,18 @@ local function verify_global_config(config)
         return false, re
     end
 
+    if config.site.tmpdir ~= nil then
+        rc, re = assert_type(config.site.tmpdir, "config.site.tmpdir", "string")
+        if not rc then
+            return false, re
+        end
+        config.site.tmpdir = e2lib.format_replace(config.site.tmpdir,
+            { u = e2lib.globals.osenv["USER"] })
+    end
+
     rc, re = e2lib.vrfy_dict_exp_keys(config.site, "e2 config.site",
         { "e2_branch", "e2_tag", "e2_server", "e2_base", "e2_location",
-          "default_extensions" })
+          "default_extensions", "tmpdir" })
     if not rc then
         return false, re
     end