2003-07-14 10:23:11 +00:00
|
|
|
#ifndef __STORE_H
|
|
|
|
#define __STORE_H
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "hash.hh"
|
2003-08-01 15:41:47 +00:00
|
|
|
#include "db.hh"
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2004-06-20 19:17:54 +00:00
|
|
|
/* A substitute is a program invocation that constructs some store
|
|
|
|
path (typically by fetching it from somewhere, e.g., from the
|
|
|
|
network). */
|
|
|
|
struct Substitute
|
|
|
|
{
|
|
|
|
/* Store expression to be normalised and realised in order to
|
|
|
|
obtain `program'. */
|
|
|
|
Path storeExpr;
|
|
|
|
|
|
|
|
/* Program to be executed to create the store path. Must be in
|
|
|
|
the output path of `storeExpr'. */
|
|
|
|
Path program;
|
|
|
|
|
|
|
|
/* Extra arguments to be passed to the program (the first argument
|
|
|
|
is the store path to be substituted). */
|
|
|
|
Strings args;
|
|
|
|
|
|
|
|
bool operator == (const Substitute & sub);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef list<Substitute> Substitutes;
|
|
|
|
|
|
|
|
|
2003-10-15 12:42:39 +00:00
|
|
|
/* Open the database environment. */
|
|
|
|
void openDB();
|
|
|
|
|
|
|
|
/* Create the required database tables. */
|
|
|
|
void initDB();
|
|
|
|
|
|
|
|
/* Get a transaction object. */
|
|
|
|
void createStoreTransaction(Transaction & txn);
|
|
|
|
|
2003-07-10 15:11:48 +00:00
|
|
|
/* Copy a path recursively. */
|
2003-10-08 15:06:59 +00:00
|
|
|
void copyPath(const Path & src, const Path & dst);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-10-10 14:46:28 +00:00
|
|
|
/* Register a successor. This function accepts a transaction handle
|
|
|
|
so that it can be enclosed in an atomic operation with calls to
|
|
|
|
registerValidPath(). This must be atomic, since if we register a
|
|
|
|
successor for a derivation without registering the paths built in
|
|
|
|
the derivation, we have a successor with dangling pointers, and if
|
|
|
|
we do it in reverse order, we can get an obstructed build (since to
|
|
|
|
rebuild the successor, the outputs paths must not exist). */
|
|
|
|
void registerSuccessor(const Transaction & txn,
|
2003-10-10 15:14:29 +00:00
|
|
|
const Path & srcPath, const Path & sucPath);
|
2003-10-10 14:46:28 +00:00
|
|
|
|
2004-06-28 10:42:57 +00:00
|
|
|
/* Remove a successor mapping. */
|
|
|
|
void unregisterSuccessor(const Path & srcPath);
|
|
|
|
|
2003-10-15 12:42:39 +00:00
|
|
|
/* Return the predecessors of the Nix expression stored at the given
|
|
|
|
path. */
|
|
|
|
bool querySuccessor(const Path & srcPath, Path & sucPath);
|
|
|
|
|
2003-10-10 15:25:21 +00:00
|
|
|
/* Return the predecessors of the Nix expression stored at the given
|
|
|
|
path. */
|
|
|
|
Paths queryPredecessors(const Path & sucPath);
|
|
|
|
|
2003-07-10 15:11:48 +00:00
|
|
|
/* Register a substitute. */
|
2004-08-31 16:13:10 +00:00
|
|
|
typedef list<pair<Path, Substitute> > SubstitutePairs;
|
|
|
|
void registerSubstitutes(const Transaction & txn,
|
|
|
|
const SubstitutePairs & subPairs);
|
2003-07-07 09:25:26 +00:00
|
|
|
|
2003-10-16 16:29:57 +00:00
|
|
|
/* Return the substitutes expression for the given path. */
|
2004-06-20 19:17:54 +00:00
|
|
|
Substitutes querySubstitutes(const Path & srcPath);
|
2003-10-16 16:29:57 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* Register the validity of a path. */
|
|
|
|
void registerValidPath(const Transaction & txn, const Path & path);
|
2003-07-21 14:46:01 +00:00
|
|
|
|
2004-04-14 08:08:55 +00:00
|
|
|
/* Throw an exception if `path' is not directly in the Nix store. */
|
|
|
|
void assertStorePath(const Path & path);
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* Checks whether a path is valid. */
|
|
|
|
bool isValidPath(const Path & path);
|
2003-07-07 09:25:26 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* Copy the contents of a path to the store and register the validity
|
|
|
|
the resulting path. The resulting path is returned. */
|
|
|
|
Path addToStore(const Path & srcPath);
|
2003-06-23 14:40:49 +00:00
|
|
|
|
2003-10-15 12:42:39 +00:00
|
|
|
/* Like addToStore, but the path of the output is given, and the
|
|
|
|
contents written to the output path is a regular file containing
|
|
|
|
the given string. */
|
|
|
|
void addTextToStore(const Path & dstPath, const string & s);
|
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
/* Delete a value from the nixStore directory. */
|
2003-10-08 15:06:59 +00:00
|
|
|
void deleteFromStore(const Path & path);
|
2003-06-23 14:40:49 +00:00
|
|
|
|
2003-07-17 12:27:55 +00:00
|
|
|
void verifyStore();
|
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-14 10:23:11 +00:00
|
|
|
#endif /* !__STORE_H */
|