From e431542a5705d3c8681b1f0b2456cbc7f74f5105 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 23 Nov 2024 18:33:19 +0100 Subject: [PATCH] chore: allow access to thawed/unpacked metadata for rewriting --- include/dwarfs/reader/filesystem_v2.h | 11 +++++++++++ include/dwarfs/reader/internal/metadata_v2.h | 11 +++++++++++ src/reader/filesystem_v2.cpp | 19 +++++++++++++++++++ src/reader/internal/metadata_v2.cpp | 8 ++++++++ 4 files changed, 49 insertions(+) diff --git a/include/dwarfs/reader/filesystem_v2.h b/include/dwarfs/reader/filesystem_v2.h index 49ed66083..4a54bea9d 100644 --- a/include/dwarfs/reader/filesystem_v2.h +++ b/include/dwarfs/reader/filesystem_v2.h @@ -52,6 +52,10 @@ class mmif; class os_access; class performance_monitor; +namespace thrift::metadata { +class metadata; +} + namespace reader { struct cache_tidy_config; @@ -347,6 +351,9 @@ class filesystem_v2 { return impl_->get_block_category(block_number); } + std::unique_ptr thawed_metadata() const; + std::unique_ptr unpacked_metadata() const; + class impl { public: virtual ~impl() = default; @@ -442,6 +449,10 @@ class filesystem_v2 { virtual std::shared_ptr get_parser() const = 0; virtual std::optional get_block_category(size_t block_number) const = 0; + virtual std::unique_ptr + thawed_metadata() const = 0; + virtual std::unique_ptr + unpacked_metadata() const = 0; }; private: diff --git a/include/dwarfs/reader/internal/metadata_v2.h b/include/dwarfs/reader/internal/metadata_v2.h index 027b69a2f..f4eac8a1d 100644 --- a/include/dwarfs/reader/internal/metadata_v2.h +++ b/include/dwarfs/reader/internal/metadata_v2.h @@ -173,6 +173,14 @@ class metadata_v2 { return impl_->get_all_gids(); } + std::unique_ptr thaw() const { + return impl_->thaw(); + } + + std::unique_ptr unpack() const { + return impl_->unpack(); + } + class impl { public: virtual ~impl() = default; @@ -244,6 +252,9 @@ class metadata_v2 { virtual std::vector get_all_uids() const = 0; virtual std::vector get_all_gids() const = 0; + + virtual std::unique_ptr thaw() const = 0; + virtual std::unique_ptr unpack() const = 0; }; private: diff --git a/src/reader/filesystem_v2.cpp b/src/reader/filesystem_v2.cpp index fe957b8ee..26e315046 100644 --- a/src/reader/filesystem_v2.cpp +++ b/src/reader/filesystem_v2.cpp @@ -316,6 +316,15 @@ class filesystem_ final : public filesystem_v2::impl { return meta_.get_block_category(block_no); } + std::unique_ptr thawed_metadata() const override { + return meta_.thaw(); + } + + std::unique_ptr + 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; @@ -1131,4 +1140,14 @@ filesystem_v2::header(std::shared_ptr mm, file_off_t image_offset) { return internal::filesystem_parser(mm, image_offset).header(); } +std::unique_ptr +filesystem_v2::thawed_metadata() const { + return impl_->thawed_metadata(); +} + +std::unique_ptr +filesystem_v2::unpacked_metadata() const { + return impl_->unpacked_metadata(); +} + } // namespace dwarfs::reader diff --git a/src/reader/internal/metadata_v2.cpp b/src/reader/internal/metadata_v2.cpp index 0777844c9..fd0440470 100644 --- a/src/reader/internal/metadata_v2.cpp +++ b/src/reader/internal/metadata_v2.cpp @@ -555,6 +555,14 @@ class metadata_ final : public metadata_v2::impl { std::vector get_all_uids() const override; std::vector get_all_gids() const override; + std::unique_ptr unpack() const override { + return std::make_unique(unpack_metadata()); + } + + std::unique_ptr thaw() const override { + return std::make_unique(meta_.thaw()); + } + private: template using set_type = folly::F14ValueSet;