mirror of
https://github.com/NixOS/nix
synced 2025-07-02 21:51:50 +02:00
* Allow unprivileged users to run the garbage collector and to do
`nix-store --delete'. But unprivileged users are not allowed to ignore liveness. * `nix-store --delete --ignore-liveness': ignore the runtime roots as well.
This commit is contained in:
parent
29cf434a35
commit
a9c4f66cfb
16 changed files with 106 additions and 56 deletions
|
@ -37,6 +37,16 @@ typedef list<Substitute> Substitutes;
|
|||
typedef std::map<Path, Path> Roots;
|
||||
|
||||
|
||||
/* Garbage collector operation. */
|
||||
typedef enum {
|
||||
gcReturnRoots,
|
||||
gcReturnLive,
|
||||
gcReturnDead,
|
||||
gcDeleteDead,
|
||||
gcDeleteSpecific,
|
||||
} GCAction;
|
||||
|
||||
|
||||
class StoreAPI
|
||||
{
|
||||
public:
|
||||
|
@ -127,6 +137,33 @@ public:
|
|||
outside of the Nix store that point to `storePath'. */
|
||||
virtual Roots findRoots() = 0;
|
||||
|
||||
/* Depending on `action', this function does the following:
|
||||
|
||||
- `gcReturnRoots': find and return the set of roots for the
|
||||
garbage collector. These are the store paths symlinked to in
|
||||
the `gcroots' directory.
|
||||
|
||||
- `gcReturnLive': return the set of paths reachable from
|
||||
(i.e. in the closure of) the roots.
|
||||
|
||||
- `gcReturnDead': return the set of paths not reachable from
|
||||
the roots.
|
||||
|
||||
- `gcDeleteDead': actually delete the latter set.
|
||||
|
||||
- `gcDeleteSpecific': delete the paths listed in
|
||||
`pathsToDelete', insofar as they are not reachable.
|
||||
|
||||
If `ignoreLiveness' is set, then reachability from the roots is
|
||||
ignored (dangerous!). However, the paths must still be
|
||||
unreferenced *within* the store (i.e., there can be no other
|
||||
store paths that depend on them).
|
||||
|
||||
For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
|
||||
number of bytes that would be or was freed is returned in
|
||||
`bytesFreed'. */
|
||||
virtual void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -177,6 +214,17 @@ std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
|||
Path computeStorePathForText(const string & suffix, const string & s);
|
||||
|
||||
|
||||
/* 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,
|
||||
bool indirect, bool allowOutsideRootsDir = false);
|
||||
|
||||
|
||||
/* For now, there is a single global store API object, but we'll
|
||||
purify that in the future. */
|
||||
extern boost::shared_ptr<StoreAPI> store;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue