From 4193d62e08964e2c26b27674e33327bf0417bab5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Oct 2003 11:55:38 +0000 Subject: * 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. --- src/util.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util.cc') 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; -- cgit 1.4.1