From 967d066d8e452e59507ebae7585d6f34a4edf687 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Aug 2012 19:14:30 -0400 Subject: nix-store --gc: Make ‘--max-freed 0’ do the right thing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, delete almost nothing (it will still remove unused links from /nix/store/.links). --- src/nix-store/nix-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nix-store') diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 82e08fecf22a..9a675fcd576a 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -583,7 +583,7 @@ static void opGC(Strings opFlags, Strings opArgs) else if (*i == "--delete") options.action = GCOptions::gcDeleteDead; else if (*i == "--max-freed") { long long maxFreed = getIntArg(*i, i, opFlags.end()); - options.maxFreed = maxFreed >= 1 ? maxFreed : 1; + options.maxFreed = maxFreed >= 0 ? maxFreed : 0; } else throw UsageError(format("bad sub-operation `%1%' in GC") % *i); -- cgit 1.4.1 From 01d56c1eeca497de247413a64a544605c53d9d41 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Aug 2012 22:34:46 -0400 Subject: Drop the block count in the garbage collector --- src/libstore/build.cc | 11 +++++------ src/libstore/gc.cc | 5 ++--- src/libstore/local-store.hh | 3 +-- src/libstore/remote-store.cc | 2 +- src/libstore/store-api.hh | 4 ---- src/libutil/util.cc | 21 ++++++++------------- src/libutil/util.hh | 3 +-- src/nix-store/nix-store.cc | 9 ++++----- src/nix-worker/nix-worker.cc | 2 +- 9 files changed, 23 insertions(+), 37 deletions(-) (limited to 'src/nix-store') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 290635695e05..91f235b7ab10 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -606,18 +606,17 @@ void getOwnership(const Path & path) } -void deletePathWrapped(const Path & path, - unsigned long long & bytesFreed, unsigned long long & blocksFreed) +void deletePathWrapped(const Path & path, unsigned long long & bytesFreed) { try { /* First try to delete it ourselves. */ - deletePath(path, bytesFreed, blocksFreed); + deletePath(path, bytesFreed); } catch (SysError & e) { /* If this failed due to a permission error, then try it with the setuid helper. */ if (haveBuildUsers() && !amPrivileged()) { getOwnership(path); - deletePath(path, bytesFreed, blocksFreed); + deletePath(path, bytesFreed); } else throw; } @@ -626,8 +625,8 @@ void deletePathWrapped(const Path & path, void deletePathWrapped(const Path & path) { - unsigned long long dummy1, dummy2; - deletePathWrapped(path, dummy1, dummy2); + unsigned long long dummy1; + deletePathWrapped(path, dummy1); } diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 7753b3fe20c0..a1bb4051cd1b 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -425,10 +425,9 @@ bool LocalStore::isActiveTempFile(const GCState & state, void LocalStore::deleteGarbage(GCState & state, const Path & path) { printMsg(lvlInfo, format("deleting `%1%'") % path); - unsigned long long bytesFreed, blocksFreed; - deletePathWrapped(path, bytesFreed, blocksFreed); + unsigned long long bytesFreed; + deletePathWrapped(path, bytesFreed); state.results.bytesFreed += bytesFreed; - state.results.blocksFreed += blocksFreed; } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 50910f353ad1..721cc6afbed5 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -304,8 +304,7 @@ void getOwnership(const Path & path); /* Like deletePath(), but changes the ownership of `path' using the setuid wrapper if necessary (and possible). */ -void deletePathWrapped(const Path & path, - unsigned long long & bytesFreed, unsigned long long & blocksFreed); +void deletePathWrapped(const Path & path, unsigned long long & bytesFreed); void deletePathWrapped(const Path & path); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index cbb70b2fd726..5e7f02749135 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -494,7 +494,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results) results.paths = readStrings(from); results.bytesFreed = readLongLong(from); - results.blocksFreed = readLongLong(from); + readLongLong(from); // obsolete } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index c0fb50f23dd2..79ae0170d700 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -65,13 +65,9 @@ struct GCResults number of bytes that would be or was freed. */ unsigned long long bytesFreed; - /* The number of file system blocks that would be or was freed. */ - unsigned long long blocksFreed; - GCResults() { bytesFreed = 0; - blocksFreed = 0; } }; diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 689fc543af31..9d8e4afed37d 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -297,8 +297,7 @@ void computePathSize(const Path & path, } -static void _deletePath(const Path & path, unsigned long long & bytesFreed, - unsigned long long & blocksFreed) +static void _deletePath(const Path & path, unsigned long long & bytesFreed) { checkInterrupt(); @@ -308,10 +307,8 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed, if (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode)) makeMutable(path); - if (!S_ISDIR(st.st_mode) && st.st_nlink == 1) { - bytesFreed += st.st_size; - blocksFreed += st.st_blocks; - } + if (!S_ISDIR(st.st_mode) && st.st_nlink == 1) + bytesFreed += st.st_blocks * 512; if (S_ISDIR(st.st_mode)) { Strings names = readDirectory(path); @@ -323,7 +320,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed, } for (Strings::iterator i = names.begin(); i != names.end(); ++i) - _deletePath(path + "/" + *i, bytesFreed, blocksFreed); + _deletePath(path + "/" + *i, bytesFreed); } if (remove(path.c_str()) == -1) @@ -333,19 +330,17 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed, void deletePath(const Path & path) { - unsigned long long dummy1, dummy2; - deletePath(path, dummy1, dummy2); + unsigned long long dummy; + deletePath(path, dummy); } -void deletePath(const Path & path, unsigned long long & bytesFreed, - unsigned long long & blocksFreed) +void deletePath(const Path & path, unsigned long long & bytesFreed) { startNest(nest, lvlDebug, format("recursively deleting path `%1%'") % path); bytesFreed = 0; - blocksFreed = 0; - _deletePath(path, bytesFreed, blocksFreed); + _deletePath(path, bytesFreed); } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 9b8656f70485..edb7c0fa6c60 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -80,8 +80,7 @@ void computePathSize(const Path & path, returns the number of bytes and blocks freed. */ void deletePath(const Path & path); -void deletePath(const Path & path, unsigned long long & bytesFreed, - unsigned long long & blocksFreed); +void deletePath(const Path & path, unsigned long long & bytesFreed); /* Make a path read-only recursively. */ void makePathReadOnly(const Path & path); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 9a675fcd576a..c182dbe49c7a 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -544,10 +544,9 @@ static void opCheckValidity(Strings opFlags, Strings opArgs) } -static string showBytes(unsigned long long bytes, unsigned long long blocks) +static string showBytes(unsigned long long bytes) { - return (format("%d bytes (%.2f MiB, %d blocks)") - % bytes % (bytes / (1024.0 * 1024.0)) % blocks).str(); + return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str(); } @@ -562,7 +561,7 @@ struct PrintFreed if (show) cout << format("%1% store paths deleted, %2% freed\n") % results.paths.size() - % showBytes(results.bytesFreed, results.blocksFreed); + % showBytes(results.bytesFreed); } }; @@ -735,7 +734,7 @@ static void showOptimiseStats(OptimiseStats & stats) { printMsg(lvlError, format("%1% freed by hard-linking %2% files; there are %3% files with equal contents out of %4% files in total") - % showBytes(stats.bytesFreed, stats.blocksFreed) + % showBytes(stats.bytesFreed) % stats.filesLinked % stats.sameContents % stats.totalFiles); diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index 74a619c71d0a..80c0d50609c7 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -503,7 +503,7 @@ static void performOp(unsigned int clientVersion, writeStrings(results.paths, to); writeLongLong(results.bytesFreed, to); - writeLongLong(results.blocksFreed, to); + writeLongLong(0, to); // obsolete break; } -- cgit 1.4.1 From a9e6752bbd888ab8fbc1cda6e4d539b2858c4cef Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 24 Aug 2012 16:58:11 -0400 Subject: Include the output name in the GC root link Output names are now appended to resulting GC symlinks, e.g. by nix-build. For backwards compatibility, if the output is named "out", nothing is appended. E.g. doing "nix-build -A foo" on a derivation that produces outputs "out", "bin" and "dev" will produce symlinks "./result", "./result-bin" and "./result-dev", respectively. --- scripts/nix-build.in | 12 ++++++------ src/libmain/shared.cc | 10 ---------- src/libmain/shared.hh | 1 - src/nix-instantiate/nix-instantiate.cc | 8 +++++--- src/nix-store/nix-store.cc | 10 +++++++--- 5 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src/nix-store') diff --git a/scripts/nix-build.in b/scripts/nix-build.in index afe0679a47d3..3ca3a1aafa6f 100755 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -46,7 +46,7 @@ Flags: --no-out-link: do not create the `result' symlink --out-link / -o NAME: create symlink NAME instead of `result' --attr / -A ATTR: select a specific attribute from the Nix expression - + --run-env: build dependencies of the specified derivation, then start a shell with the environment of the derivation --command: command to run with `--run-env' @@ -114,7 +114,7 @@ EOF push @buildArgs, "--dry-run"; $dryRun = 1; } - + elsif ($arg eq "--show-trace") { push @instArgs, $arg; } @@ -122,22 +122,22 @@ EOF elsif ($arg eq "-") { @exprs = ("-"); } - + elsif ($arg eq "--verbose" or substr($arg, 0, 2) eq "-v") { push @buildArgs, $arg; push @instArgs, $arg; $verbose = 1; } - + elsif ($arg eq "--quiet") { push @buildArgs, $arg; push @instArgs, $arg; } - + elsif ($arg eq "--run-env") { $runEnv = 1; } - + elsif ($arg eq "--command") { $n++; die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV; diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index d39816586404..026db4173af0 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -33,16 +33,6 @@ static void sigintHandler(int signo) } -Path makeRootName(const Path & gcRoot, int & counter) -{ - counter++; - if (counter == 1) - return gcRoot; - else - return (format("%1%-%2%") % gcRoot % counter).str(); -} - - void printGCWarning() { static bool haveWarned = false; diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 7849e10e3641..c69879a12356 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -26,7 +26,6 @@ MakeError(UsageError, nix::Error); class StoreAPI; /* Ugh. No better place to put this. */ -Path makeRootName(const Path & gcRoot, int & counter); void printGCWarning(); void printMissing(StoreAPI & store, const PathSet & paths); diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index d86c9fc84572..bca65d0728f5 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -64,9 +64,11 @@ void processExpr(EvalState & state, const Strings & attrPaths, Path drvPath = i->queryDrvPath(state); if (gcRoot == "") printGCWarning(); - else - drvPath = addPermRoot(*store, drvPath, - makeRootName(gcRoot, rootNr), indirectRoot); + else { + Path rootName = gcRoot; + if (++rootNr > 1) rootName += "-" + int2String(rootNr); + drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot); + } std::cout << format("%1%\n") % drvPath; } } diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index c182dbe49c7a..d7b998faebb7 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -64,15 +64,19 @@ static PathSet realisePath(const Path & path) if (isDerivation(path)) { store->buildPaths(singleton(path)); Derivation drv = derivationFromPath(*store, path); + rootNr++; PathSet outputs; foreach (DerivationOutputs::iterator, i, drv.outputs) { Path outPath = i->second.path; if (gcRoot == "") printGCWarning(); - else - outPath = addPermRoot(*store, outPath, - makeRootName(gcRoot, rootNr), indirectRoot); + else { + Path rootName = gcRoot; + if (rootNr > 1) rootName += "-" + int2String(rootNr); + if (i->first != "out") rootName += "-" + i->first; + outPath = addPermRoot(*store, outPath, rootName, indirectRoot); + } outputs.insert(outPath); } return outputs; -- cgit 1.4.1