mirror of
https://github.com/NixOS/nix.git
synced 2025-12-09 18:41:03 +01:00
Merge pull request #14273 from fzakaria/fzakaria/issue-13944
Make `nix nar [cat|ls]` lazy
This commit is contained in:
parent
27767a6094
commit
64c55961eb
5 changed files with 50 additions and 29 deletions
|
|
@ -70,26 +70,8 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
|
|||
|
||||
try {
|
||||
listing = nix::readFile(makeCacheFile(storePath.hashPart(), "ls"));
|
||||
|
||||
auto narAccessor = makeLazyNarAccessor(listing, [cacheFile](uint64_t offset, uint64_t length) {
|
||||
AutoCloseFD fd = toDescriptor(open(
|
||||
cacheFile.c_str(),
|
||||
O_RDONLY
|
||||
#ifndef _WIN32
|
||||
| O_CLOEXEC
|
||||
#endif
|
||||
));
|
||||
if (!fd)
|
||||
throw SysError("opening NAR cache file '%s'", cacheFile);
|
||||
|
||||
if (lseek(fromDescriptorReadOnly(fd.get()), offset, SEEK_SET) != (off_t) offset)
|
||||
throw SysError("seeking in '%s'", cacheFile);
|
||||
|
||||
std::string buf(length, 0);
|
||||
readFull(fd.get(), buf.data(), length);
|
||||
|
||||
return buf;
|
||||
});
|
||||
auto listingJson = nlohmann::json::parse(listing);
|
||||
auto narAccessor = makeLazyNarAccessor(listingJson, seekableGetNarBytes(cacheFile));
|
||||
|
||||
nars.emplace(storePath.hashPart(), narAccessor);
|
||||
return narAccessor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue