aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-03-27 13:45:17 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-03-27 13:45:17 +0000
commit329025253d38361ee3d13af0728f99c756c86b7a (patch)
treea54e5ebf1d76af74a06ce9bacf37af61a14f1e5e /src
parent5bb08db55b57b03608b15f599f0d5d9dbda13d74 (diff)
* Use /tmp/nix-build-<drvpath>-<counter> instead of
/tmp/nix-<pid>-<counter> for temporary build directories. This increases purity a bit: many packages store the temporary build path in their output, causing (generally unimportant) binary differences.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc2
-rw-r--r--src/libutil/util.cc20
-rw-r--r--src/libutil/util.hh3
3 files changed, 17 insertions, 8 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index a4f9c469c..e6ab6310c 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1568,7 +1568,7 @@ void DerivationGoal::startBuilder()
/* Create a temporary directory where the build will take
place. */
- tmpDir = createTempDir();
+ tmpDir = createTempDir("", "nix-build-" + baseNameOf(drvPath), false, false);
/* For convenience, set an environment pointing to the top build
directory. */
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index d0731c0b4..822c87a05 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -318,19 +318,27 @@ void makePathReadOnly(const Path & path)
}
-static Path tempName(const Path & tmpRoot, const Path & prefix)
+static Path tempName(Path tmpRoot, const Path & prefix, bool includePid,
+ int & counter)
{
- static int counter = 0;
- Path tmpRoot2 = canonPath(tmpRoot.empty() ? getEnv("TMPDIR", "/tmp") : tmpRoot, true);
- return (format("%1%/%2%-%3%-%4%") % tmpRoot2 % prefix % getpid() % counter++).str();
+ tmpRoot = canonPath(tmpRoot.empty() ? getEnv("TMPDIR", "/tmp") : tmpRoot, true);
+ if (includePid)
+ return (format("%1%/%2%-%3%-%4%") % tmpRoot % prefix % getpid() % counter++).str();
+ else
+ return (format("%1%/%2%-%3%") % tmpRoot % prefix % counter++).str();
}
-Path createTempDir(const Path & tmpRoot, const Path & prefix)
+Path createTempDir(const Path & tmpRoot, const Path & prefix,
+ bool includePid, bool useGlobalCounter)
{
+ static int globalCounter = 0;
+ int localCounter = 0;
+ int & counter(useGlobalCounter ? globalCounter : localCounter);
+
while (1) {
checkInterrupt();
- Path tmpDir = tempName(tmpRoot, prefix);
+ Path tmpDir = tempName(tmpRoot, prefix, includePid, counter);
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 657f45ced..d75002b02 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -70,7 +70,8 @@ void deletePath(const Path & path, unsigned long long & bytesFreed);
void makePathReadOnly(const Path & path);
/* Create a temporary directory. */
-Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix");
+Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
+ bool includePid = true, bool useGlobalCounter = true);
/* Create a directory and all its parents, if necessary. Returns the
list of created directories, in order of creation. */