From 6011bd0da24c100f86239ed826fa7b496bbdddf8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 9 Jul 2003 16:12:40 +0000 Subject: * Outline of the new scheme for derivate distribution. --- src/fstate.cc | 5 +++++ src/globals.hh | 15 +++++++++++++++ src/store.cc | 7 +++++-- src/store.hh | 12 ++++++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/fstate.cc b/src/fstate.cc index 2f0e50fb2d0e..e289ca7b1958 100644 --- a/src/fstate.cc +++ b/src/fstate.cc @@ -250,6 +250,10 @@ static FState realise(FState fs, StringSet & paths) /* Register the normal form. */ nf = storeSuccessor(fs, nf, paths); + /* Expand the hash into the target path. */ + expandHash(hash, path); + +#if 0 /* Perhaps the path already exists and has the right hash? */ if (pathExists(path)) { @@ -267,6 +271,7 @@ static FState realise(FState fs, StringSet & paths) copyPath(path2, path); } +#endif return nf; } diff --git a/src/globals.hh b/src/globals.hh index 2fb9fe7476d3..8d8c63bd7565 100644 --- a/src/globals.hh +++ b/src/globals.hh @@ -30,6 +30,21 @@ extern string dbHash2Paths; */ extern string dbSuccessors; +/* dbSubstitutes :: Hash -> [Hash] + + Each pair $(h, [hs])$ tells Nix that it can realise any of the + fstate expressions referenced by the hashes in $hs$ to obtain a Nix + archive that, when unpacked, will produce a path with hash $h$. + + The main purpose of this is for distributed caching of derivates. + One system can compute a derivate with hash $h$ and put it on a + website (as a Nix archive), for instance, and then another system + can register a substitute for that derivate. The substitute in + this case might be an fstate expression that fetches the Nix + archive. +*/ +extern string dbSubstitutes; + /* Path names. */ diff --git a/src/store.cc b/src/store.cc index 095d20430777..38e059a294b5 100644 --- a/src/store.cc +++ b/src/store.cc @@ -158,6 +158,9 @@ static string queryPathByHashPrefix(Hash hash, const string & prefix) } +string expandHash(const Hash & hash, const string & outPath = "") +{ + string queryPathByHash(Hash hash) { return queryPathByHashPrefix(hash, "/"); @@ -187,8 +190,8 @@ void addToStore(string srcPath, string & dstPath, Hash & hash) void deleteFromStore(const string & path) { - string prefix = nixStore + "/"; - if (string(path, 0, prefix.size()) != prefix) + string prefix = + "/"; + if (!isInPrefix(path, nixStore)) throw Error(format("path %1% is not in the store") % path); unregisterPath(path); diff --git a/src/store.hh b/src/store.hh index a83fa03045a3..f747b7ee3aa8 100644 --- a/src/store.hh +++ b/src/store.hh @@ -13,8 +13,16 @@ void copyPath(string src, string dst); /* Register a path keyed on its hash. */ Hash registerPath(const string & path, Hash hash = Hash()); -/* Query a path (any path) through its hash. */ -string queryPathByHash(Hash hash); +/* Return a path whose contents have the given hash. If outPath is + not empty, ensure that such a path is realised in outPath (if + necessary by copying from another location). If prefix is not + empty, only return a path that is an descendent of prefix. + + If no path with the given hash is known to exist in the file + system, ... +*/ +string expandHash(const Hash & hash, const string & outPath = "", + const string & prefix = "/"); /* Copy a file to the nixStore directory and register it in dbRefs. Return the hash code of the value. */ -- cgit 1.4.1