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) { if (config.writeNARListing) {
nlohmann::json j = { nlohmann::json j = {
{"version", 1}, {"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"); 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 != "") { if (cacheDir != "") {
try { try {
nlohmann::json j = listNar(narAccessor, CanonPath::root, true); nlohmann::json j = listNar(*narAccessor, CanonPath::root, true);
writeFile(makeCacheFile(hashPart, "ls"), j.dump()); writeFile(makeCacheFile(hashPart, "ls"), j.dump());
} catch (...) { } catch (...) {
ignoreExceptionExceptInterrupt(); 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 * Write a JSON representation of the contents of a NAR (except file
* contents). * contents).
*/ */
nlohmann::json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse); nlohmann::json listNar(SourceAccessor & accessor, const CanonPath & path, bool recurse);
} // namespace nix } // namespace nix

View file

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

View file

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

View file

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