From 4db0a9555e3b39600847084e1b40e0bb935c13de Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Nov 2017 14:31:28 +0100 Subject: [PATCH] nix ls-{nar,store} --json: Respect -R --- src/libstore/binary-cache-store.cc | 2 +- src/libstore/nar-accessor.cc | 10 +++++++--- src/libstore/nar-accessor.hh | 5 ++++- src/nix/ls.cc | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 9c6424a49..93caba67e 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -121,7 +121,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref makeNarAccessor(ref nar) return make_ref(nar); } -void listNar(JSONPlaceholder & res, ref accessor, const Path & path) +void listNar(JSONPlaceholder & res, ref accessor, + const Path & path, bool recurse) { auto st = accessor->stat(path); @@ -200,8 +201,11 @@ void listNar(JSONPlaceholder & res, ref accessor, const Path & path) { auto res2 = obj.object("entries"); for (auto & name : accessor->readDirectory(path)) { - auto res3 = res2.placeholder(name); - listNar(res3, accessor, path + "/" + name); + if (recurse) { + auto res3 = res2.placeholder(name); + listNar(res3, accessor, path + "/" + name, true); + } else + res2.object(name); } } break; diff --git a/src/libstore/nar-accessor.hh b/src/libstore/nar-accessor.hh index 7699cbbb5..ed8fe15ca 100644 --- a/src/libstore/nar-accessor.hh +++ b/src/libstore/nar-accessor.hh @@ -10,6 +10,9 @@ ref makeNarAccessor(ref nar); class JSONPlaceholder; -void listNar(JSONPlaceholder & res, ref accessor, const Path & path); +/* Write a JSON representation of the contents of a NAR (except file + contents). */ +void listNar(JSONPlaceholder & res, ref accessor, + const Path & path, bool recurse); } diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 5408c0929..69620595d 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -77,7 +77,7 @@ struct MixLs : virtual Args, MixJSON if (json) { JSONPlaceholder jsonRoot(std::cout); - listNar(jsonRoot, accessor, path); + listNar(jsonRoot, accessor, path, recursive); } else listText(accessor); }