forked from lix-project/lix
BinaryCacheStore::addToStore(): Add NARs to the local cache
This commit is contained in:
parent
ca580bec35
commit
b24b8ef77c
|
@ -114,8 +114,10 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
|
|||
|
||||
auto narAccessor = makeNarAccessor(nar);
|
||||
|
||||
if (accessor_)
|
||||
if (accessor_) {
|
||||
accessor_->nars.emplace(info.path, narAccessor);
|
||||
accessor_->addToCache(info.path, *nar);
|
||||
}
|
||||
|
||||
std::function<void(const Path &, JSONPlaceholder &)> recurse;
|
||||
|
||||
|
@ -160,8 +162,10 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
|
|||
}
|
||||
|
||||
else {
|
||||
if (accessor_)
|
||||
if (accessor_) {
|
||||
accessor_->nars.emplace(info.path, makeNarAccessor(nar));
|
||||
accessor_->addToCache(info.path, *nar);
|
||||
}
|
||||
}
|
||||
|
||||
/* Compress the NAR. */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -18,6 +18,10 @@ class RemoteFSAccessor : public FSAccessor
|
|||
|
||||
friend class BinaryCacheStore;
|
||||
|
||||
Path makeCacheFile(const Path & storePath);
|
||||
|
||||
void addToCache(const Path & storePath, const std::string & nar);
|
||||
|
||||
public:
|
||||
|
||||
RemoteFSAccessor(ref<Store> store,
|
||||
|
|
Loading…
Reference in a new issue