forked from lix-project/lix
* 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.
This commit is contained in:
parent
6d478597c7
commit
4193d62e08
|
@ -54,11 +54,7 @@ void runProgram(const string & program,
|
||||||
|
|
||||||
/* Create a temporary directory where the build will take
|
/* Create a temporary directory where the build will take
|
||||||
place. */
|
place. */
|
||||||
static int counter = 0;
|
string tmpDir = createTempDir();
|
||||||
string tmpDir = (format("/tmp/nix-%1%-%2%") % getpid() % counter++).str();
|
|
||||||
|
|
||||||
if (mkdir(tmpDir.c_str(), 0777) == -1)
|
|
||||||
throw SysError(format("creating directory `%1%'") % tmpDir);
|
|
||||||
|
|
||||||
AutoDelete delTmpDir(tmpDir);
|
AutoDelete delTmpDir(tmpDir);
|
||||||
|
|
||||||
|
|
20
src/util.cc
20
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;
|
Verbosity verbosity = lvlError;
|
||||||
|
|
||||||
static int nestingLevel = 0;
|
static int nestingLevel = 0;
|
||||||
|
|
|
@ -72,6 +72,9 @@ void deletePath(const string & path);
|
||||||
/* Make a path read-only recursively. */
|
/* Make a path read-only recursively. */
|
||||||
void makePathReadOnly(const string & path);
|
void makePathReadOnly(const string & path);
|
||||||
|
|
||||||
|
/* Create a temporary directory. */
|
||||||
|
string createTempDir();
|
||||||
|
|
||||||
|
|
||||||
/* Messages. */
|
/* Messages. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue