aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-03-21 17:55:57 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-03-21 17:55:57 +0100
commit1c5f73f529d83543dc776b4de4180309bfd3b4a3 (patch)
tree3f19160e2f65893c560d04a8a99b024427b86b78 /src/libstore
parent87295b9844090d76173a9f68341a4b17a7e1e7b9 (diff)
Add Store::dumpPath() method
This allows applying nix-store --verify-path to binary cache stores: NIX_REMOTE=https://cache.nixos.org nix-store --verify-path /nix/store/s5c7...
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/binary-cache-store.cc15
-rw-r--r--src/libstore/binary-cache-store.hh2
-rw-r--r--src/libstore/local-fs-store.cc6
-rw-r--r--src/libstore/local-store.cc2
-rw-r--r--src/libstore/remote-store.cc2
-rw-r--r--src/libstore/store-api.hh5
6 files changed, 26 insertions, 6 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 94f5cbabb..de456752b 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -156,10 +156,8 @@ bool BinaryCacheStore::isValidPath(const Path & storePath)
return fileExists(narInfoFileFor(storePath));
}
-void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink)
+void BinaryCacheStore::dumpPath(const Path & storePath, Sink & sink)
{
- assert(!sign);
-
auto res = readNarInfo(storePath);
auto nar = getFile(res.url);
@@ -183,6 +181,15 @@ void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink
assert(nar.size() % 8 == 0);
sink((unsigned char *) nar.c_str(), nar.size());
+}
+
+void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink)
+{
+ assert(!sign);
+
+ auto res = readNarInfo(storePath);
+
+ dumpPath(storePath, sink);
// FIXME: check integrity of NAR.
@@ -264,7 +271,7 @@ Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
StringSink sink;
Hash h;
if (recursive) {
- dumpPath(srcPath, sink, filter);
+ nix::dumpPath(srcPath, sink, filter);
h = hashString(hashAlgo, *sink.s);
} else {
auto s = readFile(srcPath);
diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh
index c99556f33..f14b4859b 100644
--- a/src/libstore/binary-cache-store.hh
+++ b/src/libstore/binary-cache-store.hh
@@ -124,6 +124,8 @@ public:
Path addTextToStore(const string & name, const string & s,
const PathSet & references, bool repair = false) override;
+ void dumpPath(const Path & path, Sink & sink) override;
+
void exportPath(const Path & path, bool sign, Sink & sink) override;
Paths importPaths(bool requireSignature, Source & source,
diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc
index 7094a50a3..87c216ec9 100644
--- a/src/libstore/local-fs-store.cc
+++ b/src/libstore/local-fs-store.cc
@@ -1,3 +1,4 @@
+#include "archive.hh"
#include "fs-accessor.hh"
#include "store-api.hh"
@@ -68,4 +69,9 @@ ref<FSAccessor> LocalFSStore::getFSAccessor()
return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this()));
}
+void LocalFSStore::dumpPath(const Path & path, Sink & sink)
+{
+ nix::dumpPath(path, sink);
+}
+
}
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 3d10b3387..532d511ef 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -1418,7 +1418,7 @@ Path LocalStore::addToStore(const string & name, const Path & _srcPath,
small files. */
StringSink sink;
if (recursive)
- dumpPath(srcPath, sink, filter);
+ nix::dumpPath(srcPath, sink, filter);
else
sink.s = make_ref<std::string>(readFile(srcPath));
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 82b7cfd7c..3c417b4a6 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -366,7 +366,7 @@ Path RemoteStore::addToStore(const string & name, const Path & _srcPath,
try {
conn->to.written = 0;
conn->to.warn = true;
- dumpPath(srcPath, conn->to, filter);
+ nix::dumpPath(srcPath, conn->to, filter);
conn->to.warn = false;
conn->processStderr();
} catch (SysError & e) {
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 72b0b0f03..9a2c9daca 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -215,6 +215,9 @@ public:
virtual Path addTextToStore(const string & name, const string & s,
const PathSet & references, bool repair = false) = 0;
+ /* Write a NAR dump of a store path. */
+ virtual void dumpPath(const Path & path, Sink & sink) = 0;
+
/* Export a store path, that is, create a NAR dump of the store
path and append its references and its deriver. Optionally, a
cryptographic signature (created by OpenSSL) of the preceding
@@ -354,6 +357,8 @@ public:
class LocalFSStore : public Store
{
+public:
+ void dumpPath(const Path & path, Sink & sink) override;
ref<FSAccessor> getFSAccessor() override;
};