1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-22 18:29:36 +01:00

listNar should just take the source accessor by simple reference

A shared pointer is not needed.
This commit is contained in:
John Ericson 2025-11-19 20:15:49 -05:00
parent d17bfe3866
commit ac36d74b66
6 changed files with 10 additions and 10 deletions

View file

@ -208,7 +208,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
if (config.writeNARListing) {
nlohmann::json j = {
{"version", 1},
{"root", listNar(ref<SourceAccessor>(narAccessor), CanonPath::root, true)},
{"root", listNar(*narAccessor, CanonPath::root, true)},
};
upsertFile(std::string(info.path.hashPart()) + ".ls", j.dump(), "application/json");

View file

@ -39,7 +39,7 @@ ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std:
if (cacheDir != "") {
try {
nlohmann::json j = listNar(narAccessor, CanonPath::root, true);
nlohmann::json j = listNar(*narAccessor, CanonPath::root, true);
writeFile(makeCacheFile(hashPart, "ls"), j.dump());
} catch (...) {
ignoreExceptionExceptInterrupt();

View file

@ -38,6 +38,6 @@ ref<SourceAccessor> makeLazyNarAccessor(const nlohmann::json & listing, GetNarBy
* Write a JSON representation of the contents of a NAR (except file
* contents).
*/
nlohmann::json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse);
nlohmann::json listNar(SourceAccessor & accessor, const CanonPath & path, bool recurse);
} // namespace nix

View file

@ -274,9 +274,9 @@ GetNarBytes seekableGetNarBytes(const Path & path)
using nlohmann::json;
json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
json listNar(SourceAccessor & accessor, const CanonPath & path, bool recurse)
{
auto st = accessor->lstat(path);
auto st = accessor.lstat(path);
json obj = json::object();
@ -295,7 +295,7 @@ json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
{
obj["entries"] = json::object();
json & res2 = obj["entries"];
for (const auto & [name, type] : accessor->readDirectory(path)) {
for (const auto & [name, type] : accessor.readDirectory(path)) {
if (recurse) {
res2[name] = listNar(accessor, path / name, true);
} else
@ -305,7 +305,7 @@ json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
break;
case SourceAccessor::Type::tSymlink:
obj["type"] = "symlink";
obj["target"] = accessor->readLink(path);
obj["target"] = accessor.readLink(path);
break;
case SourceAccessor::Type::tBlock:
case SourceAccessor::Type::tChar:

View file

@ -80,7 +80,7 @@ struct CmdCatNar : StoreCommand, MixCat
throw SysError("opening NAR file '%s'", narPath);
auto source = FdSource{fd.get()};
auto narAccessor = makeNarAccessor(source);
auto listing = listNar(narAccessor, CanonPath::root, true);
auto listing = listNar(*narAccessor, CanonPath::root, true);
cat(makeLazyNarAccessor(listing, seekableGetNarBytes(narPath)), CanonPath{path});
}
};

View file

@ -85,7 +85,7 @@ struct MixLs : virtual Args, MixJSON
if (json) {
if (showDirectory)
throw UsageError("'--directory' is useless with '--json'");
logger->cout("%s", listNar(accessor, path, recursive));
logger->cout("%s", listNar(*accessor, path, recursive));
} else
listText(accessor, std::move(path));
}
@ -150,7 +150,7 @@ struct CmdLsNar : Command, MixLs
throw SysError("opening NAR file '%s'", narPath);
auto source = FdSource{fd.get()};
auto narAccessor = makeNarAccessor(source);
auto listing = listNar(narAccessor, CanonPath::root, true);
auto listing = listNar(*narAccessor, CanonPath::root, true);
list(makeLazyNarAccessor(listing, seekableGetNarBytes(narPath)), CanonPath{path});
}
};