2003-07-14 13:23:11 +03:00
|
|
|
#ifndef __STORE_H
|
|
|
|
#define __STORE_H
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "hash.hh"
|
2003-08-01 18:41:47 +03:00
|
|
|
#include "db.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2004-06-20 22:17:54 +03: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 15:42:39 +03: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 18:11:48 +03:00
|
|
|
/* Copy a path recursively. */
|
2003-10-08 18:06:59 +03:00
|
|
|
void copyPath(const Path & src, const Path & dst);
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-10-10 17:46:28 +03: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 18:14:29 +03:00
|
|
|
const Path & srcPath, const Path & sucPath);
|
2003-10-10 17:46:28 +03:00
|
|
|
|
2003-10-15 15:42:39 +03:00
|
|
|
/* Return the predecessors of the Nix expression stored at the given
|
|
|
|
path. */
|
|
|
|
bool querySuccessor(const Path & srcPath, Path & sucPath);
|
|
|
|
|
2003-10-10 18:25:21 +03:00
|
|
|
/* Return the predecessors of the Nix expression stored at the given
|
|
|
|
path. */
|
|
|
|
Paths queryPredecessors(const Path & sucPath);
|
|
|
|
|
2003-07-10 18:11:48 +03:00
|
|
|
/* Register a substitute. */
|
2004-06-21 10:38:17 +03:00
|
|
|
void registerSubstitute(const Transaction & txn,
|
|
|
|
const Path & srcPath, const Substitute & sub);
|
2003-07-07 12:25:26 +03:00
|
|
|
|
2003-10-16 19:29:57 +03:00
|
|
|
/* Return the substitutes expression for the given path. */
|
2004-06-20 22:17:54 +03:00
|
|
|
Substitutes querySubstitutes(const Path & srcPath);
|
2003-10-16 19:29:57 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
/* Register the validity of a path. */
|
|
|
|
void registerValidPath(const Transaction & txn, const Path & path);
|
2003-07-21 17:46:01 +03:00
|
|
|
|
2004-04-14 11:08:55 +03:00
|
|
|
/* Throw an exception if `path' is not directly in the Nix store. */
|
|
|
|
void assertStorePath(const Path & path);
|
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
/* Checks whether a path is valid. */
|
|
|
|
bool isValidPath(const Path & path);
|
2003-07-07 12:25:26 +03:00
|
|
|
|
2003-10-08 18:06:59 +03: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 17:40:49 +03:00
|
|
|
|
2003-10-15 15:42:39 +03: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 16:55:12 +03:00
|
|
|
/* Delete a value from the nixStore directory. */
|
2003-10-08 18:06:59 +03:00
|
|
|
void deleteFromStore(const Path & path);
|
2003-06-23 17:40:49 +03:00
|
|
|
|
2003-07-17 15:27:55 +03:00
|
|
|
void verifyStore();
|
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-14 13:23:11 +03:00
|
|
|
#endif /* !__STORE_H */
|