* Create missing log and temproots directories automatically (reported

by Rob).
This commit is contained in:
Eelco Dolstra 2005-03-24 17:46:38 +00:00
parent d1487d9015
commit c6178f0b03
4 changed files with 25 additions and 13 deletions

View file

@ -1211,10 +1211,16 @@ void DerivationGoal::computeClosure()
} }
static string drvsLogDir = "drvs";
void DerivationGoal::openLogFile() void DerivationGoal::openLogFile()
{ {
/* Create a log file. */ /* 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(), fdLogFile = open(logFileName.c_str(),
O_CREAT | O_WRONLY | O_TRUNC, 0666); O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (fdLogFile == -1) if (fdLogFile == -1)

View file

@ -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) void createSymlink(const Path & link, const Path & target, bool careful)
{ {
/* Create directories up to `gcRoot'. */ /* Create directories up to `gcRoot'. */
@ -122,8 +112,11 @@ void addTempRoot(const Path & path)
if (fdTempRoots == -1) { if (fdTempRoots == -1) {
while (1) { while (1) {
fnTempRoots = (format("%1%/%2%/%3%") Path dir = (format("%1%/%2%") % nixStateDir % tempRootsDir).str();
% nixStateDir % tempRootsDir % getpid()).str(); createDirs(dir);
fnTempRoots = (format("%1%/%2%")
% dir % getpid()).str();
AutoCloseFD fdGCLock = openGCLock(ltRead); AutoCloseFD fdGCLock = openGCLock(ltRead);

View file

@ -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) void writeStringToFile(const Path & path, const string & s)
{ {
AutoCloseFD fd(open(path.c_str(), AutoCloseFD fd(open(path.c_str(),

View file

@ -107,6 +107,9 @@ void makePathReadOnly(const Path & path);
/* Create a temporary directory. */ /* Create a temporary directory. */
Path createTempDir(); 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 /* 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 in binary mode (i.e., no end-of-line conversions). The path should
not already exist. */ not already exist. */