diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-01 13:48:46 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-01 13:48:46 +0000 |
commit | 630ae0c9d7f65a2d6bef85a5194b4d704e54eded (patch) | |
tree | 1cbb2dce71e58abb4617239857bbd144b1f355c1 /src/nix-store/main.cc | |
parent | dcc37c236c66ba463bd61fec23d046485d8a412f (diff) |
* nix-build: use an indirection scheme to make it easier for users to
get rid of GC roots. Nix-build places a symlink `result' in the
current directory. Previously, removing that symlink would not
remove the store path being linked to as a GC root. Now, the GC
root created by nix-build is actually a symlink in
`/nix/var/nix/gcroots/auto' to `result'. So if that symlink is
removed the GC root automatically becomes invalid (since it can no
longer be resolved). The root itself is not automatically removed -
the garbage collector should delete dangling roots.
Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r-- | src/nix-store/main.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc index c1fedaf48..3edcff7ee 100644 --- a/src/nix-store/main.cc +++ b/src/nix-store/main.cc @@ -1,9 +1,5 @@ #include <iostream> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - #include "globals.hh" #include "build.hh" #include "gc.hh" @@ -24,6 +20,7 @@ void printHelp() static Path gcRoot; static int rootNr = 0; +static bool indirectRoot = false; static Path findOutput(const Derivation & drv, string id) @@ -37,11 +34,9 @@ static Path findOutput(const Derivation & drv, string id) static Path followSymlinks(Path & path) { + path = absPath(path); while (!isStorePath(path)) { - struct stat st; - if (lstat(path.c_str(), &st)) - throw SysError(format("getting status of `%1%'") % path); - if (!S_ISLNK(st.st_mode)) return path; + if (!isLink(path)) return path; string target = readLink(path); path = canonPath(string(target, 0, 1) == "/" ? target @@ -64,7 +59,9 @@ static Path realisePath(const Path & path) if (gcRoot == "") printGCWarning(); else - outPath = addPermRoot(outPath, makeRootName(gcRoot, rootNr)); + outPath = addPermRoot(outPath, + makeRootName(gcRoot, rootNr), + indirectRoot); return outPath; } else { @@ -191,6 +188,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) { + *i = followSymlinks(*i); if (forceRealise) realisePath(*i); Derivation drv = derivationFromPath(*i); cout << format("%1%\n") % findOutput(drv, "out"); @@ -206,6 +204,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) { + *i = followSymlinks(*i); Path path = maybeUseOutput(*i, useOutput, forceRealise); if (query == qRequisites) storePathRequisites(path, includeOutputs, paths); @@ -441,8 +440,10 @@ void run(Strings args) else if (arg == "--add-root") { if (i == args.end()) throw UsageError("`--add-root requires an argument"); - gcRoot = *i++; + gcRoot = absPath(*i++); } + else if (arg == "--indirect") + indirectRoot = true; else if (arg[0] == '-') opFlags.push_back(arg); else |