summaryrefslogtreecommitdiffstats
path: root/src/libstore/remote-fs-accessor.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-17 21:39:48 +0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-17 21:39:48 +0200
commitb24b8ef77c63727b9d6494fe25cfce45d57581be (patch)
tree465fd499ec54aa0cb26ec5039d14241a3c1783f8 /src/libstore/remote-fs-accessor.cc
parentca580bec35ea4d1984e36864158d7be99cfcb34b (diff)
BinaryCacheStore::addToStore(): Add NARs to the local cache
Diffstat (limited to 'src/libstore/remote-fs-accessor.cc')
-rw-r--r--src/libstore/remote-fs-accessor.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc
index da4e30b22..939691204 100644
--- a/src/libstore/remote-fs-accessor.cc
+++ b/src/libstore/remote-fs-accessor.cc
@@ -11,6 +11,19 @@ RemoteFSAccessor::RemoteFSAccessor(ref<Store> store, const Path & cacheDir)
createDirs(cacheDir);
}
+Path RemoteFSAccessor::makeCacheFile(const Path & storePath)
+{
+ assert(cacheDir != "");
+ return fmt("%s/%s.nar", cacheDir, storePathToHash(storePath));
+}
+
+void RemoteFSAccessor::addToCache(const Path & storePath, const std::string & nar)
+{
+ if (cacheDir != "")
+ /* FIXME: do this asynchronously. */
+ writeFile(makeCacheFile(storePath), nar);
+}
+
std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_)
{
auto path = canonPath(path_);
@@ -26,19 +39,14 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_)
StringSink sink;
- Path cacheFile = cacheDir != "" ? fmt("%s/%s.nar", cacheDir, storePathToHash(storePath)) : "";
-
try {
- if (cacheFile != "")
- *sink.s = nix::readFile(cacheFile);
+ if (cacheDir != "")
+ *sink.s = nix::readFile(makeCacheFile(storePath));
} catch (SysError &) { }
if (sink.s->empty()) {
store->narFromPath(storePath, sink);
-
- if (cacheFile != "")
- /* FIXME: do this asynchronously. */
- writeFile(cacheFile, *sink.s);
+ addToCache(storePath, *sink.s);
}
auto accessor = makeNarAccessor(sink.s);