mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-14 06:48:39 -04:00
feat: expose block category metadata in filesystem_v2
This commit is contained in:
parent
e3bf6bbe01
commit
82aeadc79d
@ -324,6 +324,11 @@ class filesystem_v2_lite {
|
|||||||
return lite_->get_block_category(block_number);
|
return lite_->get_block_category(block_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const {
|
||||||
|
return lite_->get_block_category_metadata(block_number);
|
||||||
|
}
|
||||||
|
|
||||||
void cache_blocks_by_category(std::string_view category) const {
|
void cache_blocks_by_category(std::string_view category) const {
|
||||||
lite_->cache_blocks_by_category(category);
|
lite_->cache_blocks_by_category(category);
|
||||||
}
|
}
|
||||||
@ -420,6 +425,8 @@ class filesystem_v2_lite {
|
|||||||
virtual std::vector<file_stat::gid_type> get_all_gids() const = 0;
|
virtual std::vector<file_stat::gid_type> get_all_gids() const = 0;
|
||||||
virtual std::optional<std::string>
|
virtual std::optional<std::string>
|
||||||
get_block_category(size_t block_number) const = 0;
|
get_block_category(size_t block_number) const = 0;
|
||||||
|
virtual std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const = 0;
|
||||||
virtual void cache_blocks_by_category(std::string_view category) const = 0;
|
virtual void cache_blocks_by_category(std::string_view category) const = 0;
|
||||||
virtual void cache_all_blocks() const = 0;
|
virtual void cache_all_blocks() const = 0;
|
||||||
virtual std::shared_ptr<internal::filesystem_parser> get_parser() const = 0;
|
virtual std::shared_ptr<internal::filesystem_parser> get_parser() const = 0;
|
||||||
|
@ -157,6 +157,11 @@ class metadata_v2 {
|
|||||||
return impl_->get_block_category(block_number);
|
return impl_->get_block_category(block_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const {
|
||||||
|
return impl_->get_block_category_metadata(block_number);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_all_block_categories() const {
|
std::vector<std::string> get_all_block_categories() const {
|
||||||
return impl_->get_all_block_categories();
|
return impl_->get_all_block_categories();
|
||||||
}
|
}
|
||||||
@ -232,6 +237,9 @@ class metadata_v2 {
|
|||||||
virtual std::optional<std::string>
|
virtual std::optional<std::string>
|
||||||
get_block_category(size_t block_number) const = 0;
|
get_block_category(size_t block_number) const = 0;
|
||||||
|
|
||||||
|
virtual std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const = 0;
|
||||||
|
|
||||||
virtual std::vector<std::string> get_all_block_categories() const = 0;
|
virtual std::vector<std::string> get_all_block_categories() const = 0;
|
||||||
|
|
||||||
virtual std::vector<file_stat::uid_type> get_all_uids() const = 0;
|
virtual std::vector<file_stat::uid_type> get_all_uids() const = 0;
|
||||||
|
@ -307,6 +307,10 @@ class filesystem_ final {
|
|||||||
std::optional<std::string> get_block_category(size_t block_no) const {
|
std::optional<std::string> get_block_category(size_t block_no) const {
|
||||||
return meta_.get_block_category(block_no);
|
return meta_.get_block_category(block_no);
|
||||||
}
|
}
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_no) const {
|
||||||
|
return meta_.get_block_category_metadata(block_no);
|
||||||
|
}
|
||||||
|
|
||||||
void cache_blocks_by_category(std::string_view category) const {
|
void cache_blocks_by_category(std::string_view category) const {
|
||||||
auto const max_blocks = get_max_cache_blocks();
|
auto const max_blocks = get_max_cache_blocks();
|
||||||
@ -689,7 +693,9 @@ void filesystem_<LoggerPolicy>::dump(std::ostream& os,
|
|||||||
|
|
||||||
std::string metadata;
|
std::string metadata;
|
||||||
|
|
||||||
if (bd) {
|
if (auto m = meta_.get_block_category_metadata(block_no)) {
|
||||||
|
metadata = fmt::format(", metadata={}", m->dump());
|
||||||
|
} else if (bd) {
|
||||||
if (auto m = bd->metadata()) {
|
if (auto m = bd->metadata()) {
|
||||||
metadata = fmt::format(", metadata={}", *m);
|
metadata = fmt::format(", metadata={}", *m);
|
||||||
}
|
}
|
||||||
@ -769,7 +775,9 @@ filesystem_<LoggerPolicy>::info_as_json(fsinfo_options const& opts,
|
|||||||
section_info["size"] = uncompressed_size;
|
section_info["size"] = uncompressed_size;
|
||||||
section_info["ratio"] = float(s.length()) / uncompressed_size;
|
section_info["ratio"] = float(s.length()) / uncompressed_size;
|
||||||
|
|
||||||
if (auto m = bd->metadata()) {
|
if (auto m = meta_.get_block_category_metadata(block_no)) {
|
||||||
|
section_info["metadata"] = *m;
|
||||||
|
} else if (auto m = bd->metadata()) {
|
||||||
section_info["metadata"] = nlohmann::json::parse(*m);
|
section_info["metadata"] = nlohmann::json::parse(*m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1328,6 +1336,10 @@ class filesystem_common_ : public Base {
|
|||||||
get_block_category(size_t block_no) const override {
|
get_block_category(size_t block_no) const override {
|
||||||
return fs_.get_block_category(block_no);
|
return fs_.get_block_category(block_no);
|
||||||
}
|
}
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_no) const override {
|
||||||
|
return fs_.get_block_category_metadata(block_no);
|
||||||
|
}
|
||||||
|
|
||||||
void cache_blocks_by_category(std::string_view category) const override {
|
void cache_blocks_by_category(std::string_view category) const override {
|
||||||
fs_.cache_blocks_by_category(category);
|
fs_.cache_blocks_by_category(category);
|
||||||
|
@ -331,6 +331,19 @@ class metadata_v2_data {
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const {
|
||||||
|
if (auto meta_json = meta_.category_metadata_json()) {
|
||||||
|
if (auto block_cat_meta = meta_.block_category_metadata()) {
|
||||||
|
if (auto it = block_cat_meta->find(block_number);
|
||||||
|
it != block_cat_meta->end()) {
|
||||||
|
return nlohmann::json::parse(meta_json.value()[it->second()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_all_block_categories() const {
|
std::vector<std::string> get_all_block_categories() const {
|
||||||
std::vector<std::string> rv;
|
std::vector<std::string> rv;
|
||||||
|
|
||||||
@ -2192,6 +2205,11 @@ class metadata_ final : public metadata_v2::impl {
|
|||||||
return data_.get_block_category(block_number);
|
return data_.get_block_category(block_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<nlohmann::json>
|
||||||
|
get_block_category_metadata(size_t block_number) const override {
|
||||||
|
return data_.get_block_category_metadata(block_number);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_all_block_categories() const override {
|
std::vector<std::string> get_all_block_categories() const override {
|
||||||
return data_.get_all_block_categories();
|
return data_.get_all_block_categories();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user