mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
* `--min-age' flag in nix-store and nix-collect-garbage to only delete
unreachable paths that haven't been used for N hours. For instance, `nix-collect-garbage --min-age 168' only deletes paths that haven't been accessed in the last week. This is useful for instance in the build farm where many derivations can be shared between consecutive builds, and we wouldn't want a garbage collect to throw them all away. We could of course register them as roots, but then we'd to unregister them at some point, which would be a pain to manage. The `--min-age' flag gives us a sort of MRU caching scheme. BUG: this really shouldn't be in gc.cc since that violates mechanism/policy separation.
This commit is contained in:
parent
fdec72c6cc
commit
eb233e728f
6 changed files with 70 additions and 17 deletions
|
@ -2,6 +2,11 @@
|
|||
#include "globals.hh"
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void followLivePaths(Path nePath, PathSet & live)
|
||||
{
|
||||
/* Just to be sure, canonicalise the path. It is important to do
|
||||
|
@ -62,16 +67,26 @@ PathSet findLivePaths(const Paths & roots)
|
|||
}
|
||||
|
||||
|
||||
PathSet findDeadPaths(const PathSet & live)
|
||||
PathSet findDeadPaths(const PathSet & live, time_t minAge)
|
||||
{
|
||||
PathSet dead;
|
||||
|
||||
startNest(nest, lvlDebug, "finding dead paths");
|
||||
|
||||
time_t now = time(0);
|
||||
|
||||
Strings storeNames = readDirectory(nixStore);
|
||||
|
||||
for (Strings::iterator i = storeNames.begin(); i != storeNames.end(); ++i) {
|
||||
Path p = canonPath(nixStore + "/" + *i);
|
||||
|
||||
if (minAge > 0) {
|
||||
struct stat st;
|
||||
if (lstat(p.c_str(), &st) != 0)
|
||||
throw SysError(format("obtaining information about `%1%'") % p);
|
||||
if (st.st_atime + minAge >= now) continue;
|
||||
}
|
||||
|
||||
if (live.find(p) == live.end()) {
|
||||
debug(format("dead path `%1%'") % p);
|
||||
dead.insert(p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue