nix ls-{nar,store} --json: Respect -R
This commit is contained in:
parent
c8155e9f5f
commit
4db0a9555e
4 changed files with 13 additions and 6 deletions
|
@ -121,7 +121,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
|
||||||
|
|
||||||
{
|
{
|
||||||
auto res = jsonRoot.placeholder("root");
|
auto res = jsonRoot.placeholder("root");
|
||||||
listNar(res, narAccessor, "");
|
listNar(res, narAccessor, "", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,8 @@ ref<FSAccessor> makeNarAccessor(ref<const std::string> nar)
|
||||||
return make_ref<NarAccessor>(nar);
|
return make_ref<NarAccessor>(nar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void listNar(JSONPlaceholder & res, ref<FSAccessor> accessor, const Path & path)
|
void listNar(JSONPlaceholder & res, ref<FSAccessor> accessor,
|
||||||
|
const Path & path, bool recurse)
|
||||||
{
|
{
|
||||||
auto st = accessor->stat(path);
|
auto st = accessor->stat(path);
|
||||||
|
|
||||||
|
@ -200,8 +201,11 @@ void listNar(JSONPlaceholder & res, ref<FSAccessor> accessor, const Path & path)
|
||||||
{
|
{
|
||||||
auto res2 = obj.object("entries");
|
auto res2 = obj.object("entries");
|
||||||
for (auto & name : accessor->readDirectory(path)) {
|
for (auto & name : accessor->readDirectory(path)) {
|
||||||
|
if (recurse) {
|
||||||
auto res3 = res2.placeholder(name);
|
auto res3 = res2.placeholder(name);
|
||||||
listNar(res3, accessor, path + "/" + name);
|
listNar(res3, accessor, path + "/" + name, true);
|
||||||
|
} else
|
||||||
|
res2.object(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,6 +10,9 @@ ref<FSAccessor> makeNarAccessor(ref<const std::string> nar);
|
||||||
|
|
||||||
class JSONPlaceholder;
|
class JSONPlaceholder;
|
||||||
|
|
||||||
void listNar(JSONPlaceholder & res, ref<FSAccessor> accessor, const Path & path);
|
/* Write a JSON representation of the contents of a NAR (except file
|
||||||
|
contents). */
|
||||||
|
void listNar(JSONPlaceholder & res, ref<FSAccessor> accessor,
|
||||||
|
const Path & path, bool recurse);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct MixLs : virtual Args, MixJSON
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
JSONPlaceholder jsonRoot(std::cout);
|
JSONPlaceholder jsonRoot(std::cout);
|
||||||
listNar(jsonRoot, accessor, path);
|
listNar(jsonRoot, accessor, path, recursive);
|
||||||
} else
|
} else
|
||||||
listText(accessor);
|
listText(accessor);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue