Expose the export magic value and move LocalStore::queryReferences to Store

This commit is contained in:
Eelco Dolstra 2016-02-15 14:48:38 +01:00
parent e03d6e0998
commit c8f4d89a34
4 changed files with 19 additions and 22 deletions

View file

@ -953,14 +953,6 @@ PathSet LocalStore::queryAllValidPaths()
} }
void LocalStore::queryReferences(const Path & path,
PathSet & references)
{
ValidPathInfo info = queryPathInfo(path);
references.insert(info.references.begin(), info.references.end());
}
void LocalStore::queryReferrers_(const Path & path, PathSet & referrers) void LocalStore::queryReferrers_(const Path & path, PathSet & referrers)
{ {
SQLiteStmtUse use(stmtQueryReferrers); SQLiteStmtUse use(stmtQueryReferrers);
@ -1493,9 +1485,6 @@ struct HashAndWriteSink : Sink
}; };
#define EXPORT_MAGIC 0x4558494e
static void checkSecrecy(const Path & path) static void checkSecrecy(const Path & path)
{ {
struct stat st; struct stat st;
@ -1532,7 +1521,7 @@ void LocalStore::exportPath(const Path & path, bool sign,
PathSet references; PathSet references;
queryReferences(path, references); queryReferences(path, references);
hashAndWriteSink << EXPORT_MAGIC << path << references << queryDeriver(path); hashAndWriteSink << exportMagic << path << references << queryDeriver(path);
if (sign) { if (sign) {
Hash hash = hashAndWriteSink.currentHash(); Hash hash = hashAndWriteSink.currentHash();
@ -1608,8 +1597,8 @@ Path LocalStore::importPath(bool requireSignature, Source & source)
restorePath(unpacked, hashAndReadSource); restorePath(unpacked, hashAndReadSource);
unsigned int magic = readInt(hashAndReadSource); uint32_t magic = readInt(hashAndReadSource);
if (magic != EXPORT_MAGIC) if (magic != exportMagic)
throw Error("Nix archive cannot be imported; wrong format"); throw Error("Nix archive cannot be imported; wrong format");
Path dstPath = readStorePath(hashAndReadSource); Path dstPath = readStorePath(hashAndReadSource);

View file

@ -108,8 +108,6 @@ public:
Hash queryPathHash(const Path & path) override; Hash queryPathHash(const Path & path) override;
void queryReferences(const Path & path, PathSet & references) override;
void queryReferrers(const Path & path, PathSet & referrers) override; void queryReferrers(const Path & path, PathSet & referrers) override;
Path queryDeriver(const Path & path) override; Path queryDeriver(const Path & path) override;

View file

@ -224,6 +224,13 @@ Path computeStorePathForText(const string & name, const string & s,
} }
void Store::queryReferences(const Path & path, PathSet & references)
{
ValidPathInfo info = queryPathInfo(path);
references.insert(info.references.begin(), info.references.end());
}
/* Return a string accepted by decodeValidPathInfo() that /* Return a string accepted by decodeValidPathInfo() that
registers the specified paths as valid. Note: it's the registers the specified paths as valid. Note: it's the
responsibility of the caller to provide a closure. */ responsibility of the caller to provide a closure. */

View file

@ -12,6 +12,13 @@
namespace nix { namespace nix {
/* Size of the hash part of store paths, in base-32 characters. */
const size_t storePathHashLen = 32; // i.e. 160 bits
/* Magic header of exportPath() output. */
const uint32_t exportMagic = 0x4558494e;
typedef std::map<Path, Path> Roots; typedef std::map<Path, Path> Roots;
@ -158,8 +165,7 @@ public:
/* Query the set of outgoing FS references for a store path. The /* Query the set of outgoing FS references for a store path. The
result is not cleared. */ result is not cleared. */
virtual void queryReferences(const Path & path, virtual void queryReferences(const Path & path, PathSet & references);
PathSet & references) = 0;
/* Queries the set of incoming FS references for a store path. /* Queries the set of incoming FS references for a store path.
The result is not cleared. */ The result is not cleared. */
@ -339,9 +345,6 @@ public:
}; };
const size_t storePathHashLen = 32; // base-32 characters, i.e. 160 bits
/* !!! These should be part of the store API, I guess. */ /* !!! These should be part of the store API, I guess. */
/* Throw an exception if `path' is not directly in the Nix store. */ /* Throw an exception if `path' is not directly in the Nix store. */