2003-07-14 12:23:11 +02:00
|
|
|
#ifndef __FSTATE_H
|
|
|
|
#define __FSTATE_H
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-07-09 17:02:03 +02:00
|
|
|
#include <set>
|
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "hash.hh"
|
2003-07-15 18:28:54 +02:00
|
|
|
#include "store.hh"
|
2003-06-16 15:33:38 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2003-06-27 15:55:12 +02:00
|
|
|
/* \section{Abstract syntax of Nix file system state expressions}
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-06-27 15:55:12 +02:00
|
|
|
A Nix file system state expression, or FState, describes a
|
|
|
|
(partial) state of the file system.
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
Slice : [Id] * [(Path, Id, [Id])] -> FState
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
(update)
|
2003-07-06 16:20:47 +02:00
|
|
|
Path(path, content, refs) specifies a file object (its full path
|
2003-06-25 17:50:37 +02: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 18:28:54 +02:00
|
|
|
Derive : [(Path, Id)] * [FStateId] * Path * [(String, String)] -> FState
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
(update)
|
2003-06-27 11:55:31 +02: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 17:50:37 +02:00
|
|
|
|
2003-06-27 15:55:12 +02:00
|
|
|
A FState expression is in {\em $f$-normal form} if all Derive nodes
|
|
|
|
have been reduced to File nodes.
|
2003-06-25 17:50:37 +02:00
|
|
|
|
2003-06-27 11:55:31 +02: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 17:50:37 +02:00
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
*/
|
|
|
|
|
2003-06-27 15:55:12 +02:00
|
|
|
typedef ATerm FState;
|
2003-06-27 11:55:31 +02:00
|
|
|
typedef ATerm Content;
|
|
|
|
|
2003-07-09 17:02:03 +02:00
|
|
|
typedef set<string> StringSet;
|
|
|
|
|
2003-07-15 18:28:54 +02: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 15:33:38 +02:00
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
|
|
|
|
#if 0
|
2003-07-08 15:22:08 +02:00
|
|
|
/* Realise an fstate expression in the file system. This requires
|
|
|
|
execution of all Derive() nodes. */
|
2003-07-09 17:02:03 +02:00
|
|
|
FState realiseFState(FState fs, StringSet & paths);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-07-08 15:22:08 +02:00
|
|
|
/* Return the path of an fstate expression. An empty string is
|
|
|
|
returned if the term is not a valid fstate expression. (!!!) */
|
|
|
|
string fstatePath(FState fs);
|
|
|
|
|
|
|
|
/* Return the paths referenced by fstate expression. */
|
2003-07-09 17:02:03 +02:00
|
|
|
void fstateRefs(FState fs, StringSet & paths);
|
2003-07-15 18:28:54 +02:00
|
|
|
#endif
|
|
|
|
|
2003-07-08 15:22:08 +02:00
|
|
|
|
2003-06-17 15:37:44 +02:00
|
|
|
/* Return a canonical textual representation of an expression. */
|
2003-06-27 15:55:12 +02:00
|
|
|
string printTerm(ATerm t);
|
2003-06-18 14:36:12 +02:00
|
|
|
|
2003-07-06 16:20:47 +02:00
|
|
|
/* Throw an exception with an error message containing the given
|
|
|
|
aterm. */
|
|
|
|
Error badTerm(const format & f, ATerm t);
|
|
|
|
|
2003-06-27 15:55:12 +02:00
|
|
|
/* Hash an aterm. */
|
|
|
|
Hash hashTerm(ATerm t);
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
/* Read an aterm from disk, given its id. */
|
|
|
|
ATerm termFromId(const FSId & id, string * p = 0);
|
2003-07-08 15:22:08 +02:00
|
|
|
|
2003-07-06 16:20:47 +02:00
|
|
|
/* Write an aterm to the Nix store directory, and return its hash. */
|
2003-07-15 18:28:54 +02:00
|
|
|
FSId writeTerm(ATerm t, const string & suffix, string * p = 0);
|
2003-07-06 16:20:47 +02:00
|
|
|
|
2003-07-10 20:48:11 +02:00
|
|
|
/* Register a successor. */
|
2003-07-15 18:28:54 +02: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-15 23:24:05 +02:00
|
|
|
void realiseSlice(const Slice & slice);
|
2003-07-10 20:48:11 +02:00
|
|
|
|
2003-07-16 00:28:27 +02:00
|
|
|
Strings fstatePaths(FSId id);
|
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2003-07-14 12:23:11 +02:00
|
|
|
#endif /* !__FSTATE_H */
|