1
1
Fork 0
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:
Farid Zakaria 2025-10-16 16:16:54 -07:00 committed by GitHub
parent 27767a6094
commit 64c55961eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 50 additions and 29 deletions

View file

@ -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;