mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 23:42:43 +01:00
Create a second Store::getFSAccessor for a single store object
This is sometimes easier / more performant to implement, and independently it is also a more convenient interface for many callers. The existing store-wide `getFSAccessor` is only used for - `nix why-depends` - the evaluator I hope we can get rid of it for those, too, and then we have the option of getting rid of the store-wide method. Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
This commit is contained in:
parent
0175f7e836
commit
a97d6d89d8
26 changed files with 125 additions and 57 deletions
|
|
@ -51,15 +51,17 @@ ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std:
|
|||
|
||||
std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPath & path)
|
||||
{
|
||||
auto [storePath, restPath_] = store->toStorePath(store->storeDir + path.abs());
|
||||
auto restPath = CanonPath(restPath_);
|
||||
|
||||
auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs());
|
||||
if (requireValidPath && !store->isValidPath(storePath))
|
||||
throw InvalidPath("path '%1%' is not a valid store path", store->printStorePath(storePath));
|
||||
return {ref{accessObject(storePath)}, CanonPath{restPath}};
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath & storePath)
|
||||
{
|
||||
auto i = nars.find(std::string(storePath.hashPart()));
|
||||
if (i != nars.end())
|
||||
return {i->second, restPath};
|
||||
return i->second;
|
||||
|
||||
std::string listing;
|
||||
Path cacheFile;
|
||||
|
|
@ -90,7 +92,7 @@ std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPat
|
|||
});
|
||||
|
||||
nars.emplace(storePath.hashPart(), narAccessor);
|
||||
return {narAccessor, restPath};
|
||||
return narAccessor;
|
||||
|
||||
} catch (SystemError &) {
|
||||
}
|
||||
|
|
@ -98,14 +100,14 @@ std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPat
|
|||
try {
|
||||
auto narAccessor = makeNarAccessor(nix::readFile(cacheFile));
|
||||
nars.emplace(storePath.hashPart(), narAccessor);
|
||||
return {narAccessor, restPath};
|
||||
return narAccessor;
|
||||
} catch (SystemError &) {
|
||||
}
|
||||
}
|
||||
|
||||
StringSink sink;
|
||||
store->narFromPath(storePath, sink);
|
||||
return {addToCache(storePath.hashPart(), std::move(sink.s)), restPath};
|
||||
return addToCache(storePath.hashPart(), std::move(sink.s));
|
||||
}
|
||||
|
||||
std::optional<SourceAccessor::Stat> RemoteFSAccessor::maybeLstat(const CanonPath & path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue