From e2ef5e07fdc142670f7f3161d3133ff04e99d342 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Nov 2006 17:43:04 +0000 Subject: * Refactoring. There is now an abstract interface class StoreAPI containing functions that operate on the Nix store. One implementation is LocalStore, which operates on the Nix store directly. The next step, to enable secure multi-user Nix, is to create a different implementation RemoteStore that talks to a privileged daemon process that uses LocalStore to perform the actual operations. --- src/libstore/store-api.hh | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/libstore/store-api.hh (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh new file mode 100644 index 000000000000..91beba50f7d2 --- /dev/null +++ b/src/libstore/store-api.hh @@ -0,0 +1,115 @@ +#ifndef __STOREAPI_H +#define __STOREAPI_H + +#include + +#include + +#include "hash.hh" + + +namespace nix { + + +/* A substitute is a program invocation that constructs some store + path (typically by fetching it from somewhere, e.g., from the + network). */ +struct Substitute +{ + /* The derivation that built this store path (empty if none). */ + Path deriver; + + /* 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) const; +}; + +typedef list Substitutes; + + +class StoreAPI +{ +public: + + virtual ~StoreAPI() { } + + /* Checks whether a path is valid. */ + virtual bool isValidPath(const Path & path) = 0; + + /* Return the substitutes for the given path. */ + virtual Substitutes querySubstitutes(const Path & srcPath) = 0; + + /* Queries the hash of a valid path. */ + virtual Hash queryPathHash(const Path & path) = 0; + + /* Queries the set of outgoing FS references for a store path. + The result is not cleared. */ + virtual void queryReferences(const Path & storePath, + PathSet & references) = 0; + + /* Queries the set of incoming FS references for a store path. + The result is not cleared. */ + virtual void queryReferrers(const Path & storePath, + PathSet & referrers) = 0; + + /* Copy the contents of a path to the store and register the + validity the resulting path. The resulting path is + returned. */ + virtual Path addToStore(const Path & srcPath) = 0; + + /* Like addToStore(), but for pre-adding the outputs of + fixed-output derivations. */ + virtual Path addToStoreFixed(bool recursive, string hashAlgo, + const Path & srcPath) = 0; + + /* Like addToStore, but the contents written to the output path is + a regular file containing the given string. */ + virtual Path addTextToStore(const string & suffix, const string & s, + const PathSet & references) = 0; +}; + + +/* !!! These should be part of the store API, I guess. */ + +/* Throw an exception if `path' is not directly in the Nix store. */ +void assertStorePath(const Path & path); + +bool isInStore(const Path & path); +bool isStorePath(const Path & path); + +void checkStoreName(const string & name); + +/* Chop off the parts after the top-level store name, e.g., + /nix/store/abcd-foo/bar => /nix/store/abcd-foo. */ +Path toStorePath(const Path & path); + + +/* Constructs a unique store path name. */ +Path makeStorePath(const string & type, + const Hash & hash, const string & suffix); + +Path makeFixedOutputPath(bool recursive, + string hashAlgo, Hash hash, string name); + + +/* For now, there is a single global store API object, but we'll + purify that in the future. */ +extern boost::shared_ptr store; + + +/* Factory method: open the Nix database, either through the local or + remote implementation. */ +boost::shared_ptr openStore(bool reserveSpace = true); + + + +} + + +#endif /* !__STOREAPI_H */ -- cgit 1.4.1