From 40d9eb14dfb842c51e9f86818b43ae7711e1a5d6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 22 Nov 2003 15:58:34 +0000 Subject: * Fix the garbage collector. --- src/libstore/store.cc | 9 +-------- src/libutil/util.cc | 11 +++++++++++ src/libutil/util.hh | 5 +++++ src/nix-env/main.cc | 4 +++- 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/libstore/store.cc b/src/libstore/store.cc index c83316cf6ad5..caaa293a6f1c 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -1,9 +1,6 @@ #include -#include -#include #include -#include #include #include "store.hh" @@ -307,11 +304,7 @@ void addTextToStore(const Path & dstPath, const string & s) PathLocks outputLock(lockPaths); if (!isValidPath(dstPath)) { - - AutoCloseFD fd = open(dstPath.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666); - if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath); - - writeFull(fd, (unsigned char *) s.c_str(), s.size()); + writeStringToFile(dstPath, s); Transaction txn(nixDB); registerValidPath(txn, dstPath); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 6a032a3f10f3..60b86b162c9c 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include "util.hh" @@ -192,6 +193,16 @@ Path createTempDir() } +void writeStringToFile(const Path & path, const string & s) +{ + AutoCloseFD fd = open(path.c_str(), + O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd == -1) + throw SysError(format("creating file `%1%'") % path); + writeFull(fd, (unsigned char *) s.c_str(), s.size()); +} + + Verbosity verbosity = lvlError; static int nestingLevel = 0; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index d0e7b3ada873..cca93cdc737a 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -87,6 +87,11 @@ void makePathReadOnly(const Path & path); /* Create a temporary directory. */ Path createTempDir(); +/* 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. */ +void writeStringToFile(const Path & path, const string & s); + /* Messages. */ diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 73166964fe9b..a8377582ca49 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -139,6 +139,8 @@ Path createLink(Path outPath, Path drvPath) num++; } + writeStringToFile(linkPath + "-src.id", drvPath); + return linkPath; } @@ -290,7 +292,7 @@ void uninstallDerivations(EvalState & state, Strings drvNames) installedDrvs.erase(j->second); } - createUserEnv(state, installedDrvs); + createUserEnv(state, installedDrvs); } -- cgit 1.4.1