diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-11-14T13·23+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-11-14T13·23+0100 |
commit | bac8055652964d9ad5202011befb6b199463ddef (patch) | |
tree | b37165578b2e6b5bf0c0739af636acbfa63c0be9 /src/libstore/binary-cache-store.cc | |
parent | c0d93a01ee996427a1ec6b7602e655c8405624d9 (diff) |
nix ls-{store,nar}: Add --json flag
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 35 |
1 files changed, 1 insertions, 34 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 67607ab3d43a..9c6424a496e6 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -119,42 +119,9 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str accessor_->addToCache(info.path, *nar); } - std::function<void(const Path &, JSONPlaceholder &)> recurse; - - recurse = [&](const Path & path, JSONPlaceholder & res) { - auto st = narAccessor->stat(path); - - auto obj = res.object(); - - switch (st.type) { - case FSAccessor::Type::tRegular: - obj.attr("type", "regular"); - obj.attr("size", st.fileSize); - if (st.isExecutable) - obj.attr("executable", true); - break; - case FSAccessor::Type::tDirectory: - obj.attr("type", "directory"); - { - auto res2 = obj.object("entries"); - for (auto & name : narAccessor->readDirectory(path)) { - auto res3 = res2.placeholder(name); - recurse(path + "/" + name, res3); - } - } - break; - case FSAccessor::Type::tSymlink: - obj.attr("type", "symlink"); - obj.attr("target", narAccessor->readLink(path)); - break; - default: - abort(); - } - }; - { auto res = jsonRoot.placeholder("root"); - recurse("", res); + listNar(res, narAccessor, ""); } } |