aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc8
-rw-r--r--src/libstore/gc.cc17
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/util.hh3
4 files changed, 25 insertions, 13 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index fd104dffd..4c03da3e2 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1211,10 +1211,16 @@ void DerivationGoal::computeClosure()
}
+static string drvsLogDir = "drvs";
+
+
void DerivationGoal::openLogFile()
{
/* Create a log file. */
- Path logFileName = nixLogDir + "/drvs/" + baseNameOf(drvPath);
+ Path dir = (format("%1%/%2%") % nixLogDir % drvsLogDir).str();
+ createDirs(dir);
+
+ Path logFileName = (format("%1%/%2%") % dir % baseNameOf(drvPath)).str();
fdLogFile = open(logFileName.c_str(),
O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (fdLogFile == -1)
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index e1075d025..7f0b07946 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -43,16 +43,6 @@ static int openGCLock(LockType lockType)
}
-static void createDirs(const Path & path)
-{
- if (path == "") return;
- createDirs(dirOf(path));
- if (!pathExists(path))
- if (mkdir(path.c_str(), 0777) == -1)
- throw SysError(format("creating directory `%1%'") % path);
-}
-
-
void createSymlink(const Path & link, const Path & target, bool careful)
{
/* Create directories up to `gcRoot'. */
@@ -122,8 +112,11 @@ void addTempRoot(const Path & path)
if (fdTempRoots == -1) {
while (1) {
- fnTempRoots = (format("%1%/%2%/%3%")
- % nixStateDir % tempRootsDir % getpid()).str();
+ Path dir = (format("%1%/%2%") % nixStateDir % tempRootsDir).str();
+ createDirs(dir);
+
+ fnTempRoots = (format("%1%/%2%")
+ % dir % getpid()).str();
AutoCloseFD fdGCLock = openGCLock(ltRead);
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 27df7a1aa..65c3b1539 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -271,6 +271,16 @@ Path createTempDir()
}
+void createDirs(const Path & path)
+{
+ if (path == "") return;
+ createDirs(dirOf(path));
+ if (!pathExists(path))
+ if (mkdir(path.c_str(), 0777) == -1)
+ throw SysError(format("creating directory `%1%'") % path);
+}
+
+
void writeStringToFile(const Path & path, const string & s)
{
AutoCloseFD fd(open(path.c_str(),
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 2577f79e1..beb98fe7c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -107,6 +107,9 @@ void makePathReadOnly(const Path & path);
/* Create a temporary directory. */
Path createTempDir();
+/* Create a directory and all its parents, if necessary. */
+void createDirs(const Path & path);
+
/* Create a file and write the given text to it. The file is written
in binary mode (i.e., no end-of-line conversions). The path should
not already exist. */