about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 7671c7c7e460..1576e1e8b0f2 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -317,19 +317,19 @@ void makePathReadOnly(const Path & path)
 }
 
 
-static Path tempName()
+static Path tempName(const Path & tmpRoot)
 {
     static int counter = 0;
-    Path tmpRoot = canonPath(getEnv("TMPDIR", "/tmp"), true);
-    return (format("%1%/nix-%2%-%3%") % tmpRoot % getpid() % counter++).str();
+    Path tmpRoot2 = canonPath(tmpRoot.empty() ? getEnv("TMPDIR", "/tmp") : tmpRoot, true);
+    return (format("%1%/nix-%2%-%3%") % tmpRoot2 % getpid() % counter++).str();
 }
 
 
-Path createTempDir()
+Path createTempDir(const Path & tmpRoot)
 {
     while (1) {
         checkInterrupt();
-	Path tmpDir = tempName();
+	Path tmpDir = tempName(tmpRoot);
 	if (mkdir(tmpDir.c_str(), 0777) == 0) {
 	    /* Explicitly set the group of the directory.  This is to
 	       work around around problems caused by BSD's group