forked from lix-project/lix
dcc37c236c
immediately add the result as a permanent GC root. This is the only way to prevent a race with the garbage collector. For instance, the old style ln -s $(nix-store -r $(nix-instantiate foo.nix)) \ /nix/var/nix/gcroots/result has two time windows in which the garbage collector can interfere (by GC'ing the derivation and the output, respectively). On the other hand, nix-store --add-root /nix/var/nix/gcroots/result -r \ $(nix-instantiate --add-root /nix/var/nix/gcroots/drv \ foo.nix) is safe. * nix-build: use `--add-root' to prevent GC races.
34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
#ifndef __GC_H
|
|
#define __GC_H
|
|
|
|
#include "util.hh"
|
|
|
|
|
|
/* Garbage collector operation. */
|
|
typedef enum { gcReturnLive, gcReturnDead, gcDeleteDead } GCAction;
|
|
|
|
/* If `action' is set to `soReturnLive', return the set of paths
|
|
reachable from (i.e. in the closure of) the specified roots. If
|
|
`action' is `soReturnDead', return the set of paths not reachable
|
|
from the roots. If `action' is `soDeleteDead', actually delete the
|
|
latter set. */
|
|
void collectGarbage(const PathSet & roots, GCAction action,
|
|
PathSet & result);
|
|
|
|
/* Register a temporary GC root. This root will automatically
|
|
disappear when this process exits. WARNING: this function should
|
|
not be called inside a BDB transaction, otherwise we can
|
|
deadlock. */
|
|
void addTempRoot(const Path & path);
|
|
|
|
/* Remove the temporary roots file for this process. Any temporary
|
|
root becomes garbage after this point unless it has been registered
|
|
as a (permanent) root. */
|
|
void removeTempRoots();
|
|
|
|
/* Register a permanent GC root. */
|
|
Path addPermRoot(const Path & storePath, const Path & gcRoot);
|
|
|
|
|
|
#endif /* !__GC_H */
|