2003-07-14 13:23:11 +03:00
|
|
|
#ifndef __FSTATE_H
|
|
|
|
#define __FSTATE_H
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "hash.hh"
|
2003-07-15 19:28:54 +03:00
|
|
|
#include "store.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
/* \section{Abstract syntax of Nix file system state expressions}
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
A Nix file system state expression, or FState, describes a
|
|
|
|
(partial) state of the file system.
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
Slice : [Id] * [(Path, Id, [Id])] -> FState
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
(update)
|
2003-07-06 17:20:47 +03:00
|
|
|
Path(path, content, refs) specifies a file object (its full path
|
2003-06-25 18:50:37 +03:00
|
|
|
and contents), along with all file objects referenced by it (that
|
|
|
|
is, that it has pointers to). We assume that all files are
|
|
|
|
self-referential. This prevents us from having to deal with
|
|
|
|
cycles.
|
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
Derive : [(Path, Id)] * [FStateId] * Path * [(String, String)] -> FState
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
(update)
|
2003-06-27 12:55:31 +03:00
|
|
|
Derive(platform, builder, ins, outs, env) specifies the creation of
|
|
|
|
new file objects (in paths declared by `outs') by the execution of
|
|
|
|
a program `builder' on a platform `platform'. This execution takes
|
|
|
|
place in a file system state given by `ins'. `env' specifies a
|
|
|
|
mapping of strings to strings.
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
A FState expression is in {\em $f$-normal form} if all Derive nodes
|
|
|
|
have been reduced to File nodes.
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-06-27 12:55:31 +03:00
|
|
|
DISCUSSION: the idea is that a Regular/Directory is interchangeable
|
|
|
|
with its CHash. This would appear to break referential
|
|
|
|
transparency, e.g., Derive(..., ..., [...CHash(h)...], ...) can
|
|
|
|
only be reduced in a context were the Regular/Directory equivalent
|
|
|
|
of Hash(h) is known. However, CHash should be viewed strictly as a
|
|
|
|
shorthand; that is, when we export an expression containing a
|
|
|
|
CHash, we should also export the file object referenced by that
|
|
|
|
CHash.
|
2003-06-25 18:50:37 +03:00
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
*/
|
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
typedef ATerm FState;
|
2003-06-27 12:55:31 +03:00
|
|
|
typedef ATerm Content;
|
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
typedef list<FSId> FSIds;
|
|
|
|
|
|
|
|
|
|
|
|
struct SliceElem
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
FSId id;
|
|
|
|
FSIds refs;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef list<SliceElem> SliceElems;
|
|
|
|
|
|
|
|
struct Slice
|
|
|
|
{
|
|
|
|
FSIds roots;
|
|
|
|
SliceElems elems;
|
|
|
|
};
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2003-06-17 16:37:44 +03:00
|
|
|
/* Return a canonical textual representation of an expression. */
|
2003-06-27 16:55:12 +03:00
|
|
|
string printTerm(ATerm t);
|
2003-06-18 15:36:12 +03:00
|
|
|
|
2003-07-06 17:20:47 +03:00
|
|
|
/* Throw an exception with an error message containing the given
|
|
|
|
aterm. */
|
|
|
|
Error badTerm(const format & f, ATerm t);
|
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
/* Hash an aterm. */
|
|
|
|
Hash hashTerm(ATerm t);
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
/* Read an aterm from disk, given its id. */
|
|
|
|
ATerm termFromId(const FSId & id, string * p = 0);
|
2003-07-08 16:22:08 +03:00
|
|
|
|
2003-07-06 17:20:47 +03:00
|
|
|
/* Write an aterm to the Nix store directory, and return its hash. */
|
2003-07-15 19:28:54 +03:00
|
|
|
FSId writeTerm(ATerm t, const string & suffix, string * p = 0);
|
2003-07-06 17:20:47 +03:00
|
|
|
|
2003-07-10 21:48:11 +03:00
|
|
|
/* Register a successor. */
|
2003-07-15 19:28:54 +03:00
|
|
|
void registerSuccessor(const FSId & id1, const FSId & id2);
|
|
|
|
|
|
|
|
|
|
|
|
/* Normalise an fstate-expression, that is, return an equivalent
|
|
|
|
Slice. */
|
|
|
|
Slice normaliseFState(FSId id);
|
|
|
|
|
|
|
|
/* Realise a Slice in the file system. */
|
2003-07-16 00:24:05 +03:00
|
|
|
void realiseSlice(const Slice & slice);
|
2003-07-10 21:48:11 +03:00
|
|
|
|
2003-07-16 14:05:59 +03:00
|
|
|
/* Get the list of root (output) paths of the given
|
|
|
|
fstate-expression. */
|
|
|
|
Strings fstatePaths(const FSId & id, bool normalise);
|
|
|
|
|
|
|
|
/* Get the list of paths referenced by the given fstate-expression. */
|
|
|
|
StringSet fstateRefs(const FSId & id);
|
2003-07-16 01:28:27 +03:00
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-14 13:23:11 +03:00
|
|
|
#endif /* !__FSTATE_H */
|