Skip to content

Commit

Permalink
chore: allow access to thawed/unpacked metadata for rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Nov 23, 2024
1 parent c29b3de commit e431542
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/dwarfs/reader/filesystem_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class mmif;
class os_access;
class performance_monitor;

namespace thrift::metadata {
class metadata;
}

namespace reader {

struct cache_tidy_config;
Expand Down Expand Up @@ -347,6 +351,9 @@ class filesystem_v2 {
return impl_->get_block_category(block_number);
}

std::unique_ptr<thrift::metadata::metadata> thawed_metadata() const;
std::unique_ptr<thrift::metadata::metadata> unpacked_metadata() const;

class impl {
public:
virtual ~impl() = default;
Expand Down Expand Up @@ -442,6 +449,10 @@ class filesystem_v2 {
virtual std::shared_ptr<internal::filesystem_parser> get_parser() const = 0;
virtual std::optional<std::string>
get_block_category(size_t block_number) const = 0;
virtual std::unique_ptr<thrift::metadata::metadata>
thawed_metadata() const = 0;
virtual std::unique_ptr<thrift::metadata::metadata>
unpacked_metadata() const = 0;
};

private:
Expand Down
11 changes: 11 additions & 0 deletions include/dwarfs/reader/internal/metadata_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class metadata_v2 {
return impl_->get_all_gids();
}

std::unique_ptr<thrift::metadata::metadata> thaw() const {
return impl_->thaw();
}

std::unique_ptr<thrift::metadata::metadata> unpack() const {
return impl_->unpack();
}

class impl {
public:
virtual ~impl() = default;
Expand Down Expand Up @@ -244,6 +252,9 @@ class metadata_v2 {
virtual std::vector<file_stat::uid_type> get_all_uids() const = 0;

virtual std::vector<file_stat::gid_type> get_all_gids() const = 0;

virtual std::unique_ptr<thrift::metadata::metadata> thaw() const = 0;
virtual std::unique_ptr<thrift::metadata::metadata> unpack() const = 0;
};

private:
Expand Down
19 changes: 19 additions & 0 deletions src/reader/filesystem_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ class filesystem_ final : public filesystem_v2::impl {
return meta_.get_block_category(block_no);
}

std::unique_ptr<thrift::metadata::metadata> thawed_metadata() const override {
return meta_.thaw();
}

std::unique_ptr<thrift::metadata::metadata>
unpacked_metadata() const override {
return meta_.unpack();
}

private:
filesystem_info const* get_info(fsinfo_options const& opts) const;
void check_section(fs_section const& section) const;
Expand Down Expand Up @@ -1131,4 +1140,14 @@ filesystem_v2::header(std::shared_ptr<mmif> mm, file_off_t image_offset) {
return internal::filesystem_parser(mm, image_offset).header();
}

std::unique_ptr<thrift::metadata::metadata>
filesystem_v2::thawed_metadata() const {
return impl_->thawed_metadata();
}

std::unique_ptr<thrift::metadata::metadata>
filesystem_v2::unpacked_metadata() const {
return impl_->unpacked_metadata();
}

} // namespace dwarfs::reader
8 changes: 8 additions & 0 deletions src/reader/internal/metadata_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ class metadata_ final : public metadata_v2::impl {
std::vector<file_stat::uid_type> get_all_uids() const override;
std::vector<file_stat::gid_type> get_all_gids() const override;

std::unique_ptr<thrift::metadata::metadata> unpack() const override {
return std::make_unique<thrift::metadata::metadata>(unpack_metadata());
}

std::unique_ptr<thrift::metadata::metadata> thaw() const override {
return std::make_unique<thrift::metadata::metadata>(meta_.thaw());
}

private:
template <typename K>
using set_type = folly::F14ValueSet<K>;
Expand Down

0 comments on commit e431542

Please sign in to comment.