diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 10 | ||||
-rw-r--r-- | src/libutil/util.hh | 2 |
2 files changed, 6 insertions, 6 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 diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 0ebf6f5a5f65..3c4629957a7b 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -70,7 +70,7 @@ void deletePath(const Path & path, unsigned long long & bytesFreed); void makePathReadOnly(const Path & path); /* Create a temporary directory. */ -Path createTempDir(); +Path createTempDir(const Path & tmpRoot = ""); /* Create a directory and all its parents, if necessary. */ void createDirs(const Path & path); |