aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/remote-fs-accessor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/remote-fs-accessor.cc')
-rw-r--r--src/libstore/remote-fs-accessor.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc
index f43456f0b..0ce335646 100644
--- a/src/libstore/remote-fs-accessor.cc
+++ b/src/libstore/remote-fs-accessor.cc
@@ -22,9 +22,18 @@ Path RemoteFSAccessor::makeCacheFile(std::string_view hashPart, const std::strin
return fmt("%s/%s.%s", cacheDir, hashPart, ext);
}
-void RemoteFSAccessor::addToCache(std::string_view hashPart, const std::string & nar,
- ref<FSAccessor> narAccessor)
+ref<FSAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std::string && nar)
{
+ if (cacheDir != "") {
+ try {
+ /* FIXME: do this asynchronously. */
+ writeFile(makeCacheFile(hashPart, "nar"), nar);
+ } catch (...) {
+ ignoreException();
+ }
+ }
+
+ auto narAccessor = makeNarAccessor(std::move(nar));
nars.emplace(hashPart, narAccessor);
if (cacheDir != "") {
@@ -33,14 +42,12 @@ void RemoteFSAccessor::addToCache(std::string_view hashPart, const std::string &
JSONPlaceholder jsonRoot(str);
listNar(jsonRoot, narAccessor, "", true);
writeFile(makeCacheFile(hashPart, "ls"), str.str());
-
- /* FIXME: do this asynchronously. */
- writeFile(makeCacheFile(hashPart, "nar"), nar);
-
} catch (...) {
ignoreException();
}
}
+
+ return narAccessor;
}
std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, bool requireValidPath)
@@ -55,7 +62,6 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, boo
auto i = nars.find(std::string(storePath.hashPart()));
if (i != nars.end()) return {i->second, restPath};
- StringSink sink;
std::string listing;
Path cacheFile;
@@ -86,19 +92,15 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, boo
} catch (SysError &) { }
try {
- *sink.s = nix::readFile(cacheFile);
-
- auto narAccessor = makeNarAccessor(sink.s);
+ auto narAccessor = makeNarAccessor(nix::readFile(cacheFile));
nars.emplace(storePath.hashPart(), narAccessor);
return {narAccessor, restPath};
-
} catch (SysError &) { }
}
+ StringSink sink;
store->narFromPath(storePath, sink);
- auto narAccessor = makeNarAccessor(sink.s);
- addToCache(storePath.hashPart(), *sink.s, narAccessor);
- return {narAccessor, restPath};
+ return {addToCache(storePath.hashPart(), std::move(sink.s)), restPath};
}
FSAccessor::Stat RemoteFSAccessor::stat(const Path & path)