Skip to content

Commit

Permalink
fix: only add version info to JSON metadata if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 24, 2024
1 parent dc388bc commit 4900271
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions src/reader/filesystem_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,16 @@ nlohmann::json
filesystem_<LoggerPolicy>::info_as_json(fsinfo_options const& opts) const {
filesystem_parser parser(mm_, image_offset_);

nlohmann::json info{
{"version",
{
{"major", parser.major_version()},
{"minor", parser.minor_version()},
{"header", parser.header_version()},
}},
{"image_offset", parser.image_offset()},
};
auto info = nlohmann::json::object();

if (opts.features.has(fsinfo_feature::version)) {
info["version"] = nlohmann::json::object({
{"major", parser.major_version()},
{"minor", parser.minor_version()},
{"header", parser.header_version()},
});
info["image_offset"] = parser.image_offset();
}

if (opts.features.has(fsinfo_feature::history)) {
info["history"] = history_.as_json();
Expand Down
10 changes: 5 additions & 5 deletions test/dwarfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,12 @@ void basic_end_to_end_test(
auto info = fs.info_as_json(
{.features = reader::fsinfo_features::for_level(detail)});

ASSERT_TRUE(info.count("version"));
ASSERT_TRUE(info.count("image_offset"));
ASSERT_TRUE(info.count("created_on"));
ASSERT_TRUE(info.count("created_by"));

if (detail >= 1) {
ASSERT_TRUE(info.count("version"));
ASSERT_TRUE(info.count("image_offset"));
ASSERT_TRUE(info.count("created_on"));
ASSERT_TRUE(info.count("created_by"));

ASSERT_TRUE(info.count("block_count"));
ASSERT_TRUE(info.count("block_size"));
ASSERT_TRUE(info.count("compressed_block_size"));
Expand Down

0 comments on commit 4900271

Please sign in to comment.