about summary refs log tree commit diff
path: root/src/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-10-02T11·55+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-10-02T11·55+0000
commit4193d62e08964e2c26b27674e33327bf0417bab5 (patch)
tree682be5e80e0ea2b3adaa0f715974549d9d88d2fc /src/util.cc
parent6d478597c7672efc546b6720c8404ffb5f998612 (diff)
* Nix now respects $TMPDIR for the creation of temporary build directories.
* Retry creation of a temporary directory (with a different name) in the 
  case of EEXIST.

Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index bedd031def3d..ed7562a29d73 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -171,6 +171,26 @@ void makePathReadOnly(const string & path)
 }
 
 
+static string tempName()
+{
+    static int counter = 0;
+    char * s = getenv("TMPDIR");
+    string tmpRoot = s ? canonPath(string(s)) : "/tmp";
+    return (format("%1%/nix-%2%-%3%") % tmpRoot % getpid() % counter++).str();
+}
+
+
+string createTempDir()
+{
+    while (1) {
+	string tmpDir = tempName();
+	if (mkdir(tmpDir.c_str(), 0777) == 0) return tmpDir;
+	if (errno != EEXIST)
+	    throw SysError(format("creating directory `%1%'") % tmpDir);
+    }
+}
+
+
 Verbosity verbosity = lvlError;
 
 static int nestingLevel = 0;