From d6bd917fae1d944f371ac99b858df5737a407c7c Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Wed, 7 Feb 2024 17:30:44 +0100 Subject: [PATCH] feat(filesystem): add get_all_uids() and get_all_gids() methods --- include/dwarfs/filesystem_v2.h | 10 ++++++++++ include/dwarfs/metadata_v2.h | 12 ++++++++++++ src/dwarfs/filesystem_v2.cpp | 6 ++++++ src/dwarfs/metadata_v2.cpp | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/include/dwarfs/filesystem_v2.h b/include/dwarfs/filesystem_v2.h index 7c3f937a..4a17bda4 100644 --- a/include/dwarfs/filesystem_v2.h +++ b/include/dwarfs/filesystem_v2.h @@ -189,6 +189,14 @@ class filesystem_v2 { return impl_->get_all_block_categories(); } + std::vector get_all_uids() const { + return impl_->get_all_uids(); + } + + std::vector get_all_gids() const { + return impl_->get_all_gids(); + } + void rewrite(progress& prog, filesystem_writer& writer, category_resolver const& cat_resolver, rewrite_options const& opts) const { @@ -241,6 +249,8 @@ class filesystem_v2 { virtual history const& get_history() const = 0; virtual folly::dynamic get_inode_info(inode_view entry) const = 0; virtual std::vector get_all_block_categories() const = 0; + virtual std::vector get_all_uids() const = 0; + virtual std::vector get_all_gids() const = 0; virtual void rewrite(progress& prog, filesystem_writer& writer, category_resolver const& cat_resolver, rewrite_options const& opts) const = 0; diff --git a/include/dwarfs/metadata_v2.h b/include/dwarfs/metadata_v2.h index 4cc31690..d328fbe2 100644 --- a/include/dwarfs/metadata_v2.h +++ b/include/dwarfs/metadata_v2.h @@ -151,6 +151,14 @@ class metadata_v2 { return impl_->get_all_block_categories(); } + std::vector get_all_uids() const { + return impl_->get_all_uids(); + } + + std::vector get_all_gids() const { + return impl_->get_all_gids(); + } + static std::pair, std::vector> freeze(const thrift::metadata::metadata& data); @@ -216,6 +224,10 @@ class metadata_v2 { get_block_category(size_t block_number) const = 0; virtual std::vector get_all_block_categories() const = 0; + + virtual std::vector get_all_uids() const = 0; + + virtual std::vector get_all_gids() const = 0; }; private: diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index ae85e1a2..6690df36 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -433,6 +433,12 @@ class filesystem_ final : public filesystem_v2::impl { std::vector get_all_block_categories() const override { return meta_.get_all_block_categories(); } + std::vector get_all_uids() const override { + return meta_.get_all_uids(); + } + std::vector get_all_gids() const override { + return meta_.get_all_gids(); + } void rewrite(progress& prog, filesystem_writer& writer, category_resolver const& cat_resolver, rewrite_options const& opts) const override; diff --git a/src/dwarfs/metadata_v2.cpp b/src/dwarfs/metadata_v2.cpp index db322556..9241bc46 100644 --- a/src/dwarfs/metadata_v2.cpp +++ b/src/dwarfs/metadata_v2.cpp @@ -534,6 +534,8 @@ class metadata_ final : public metadata_v2::impl { get_block_category(size_t block_number) const override; std::vector get_all_block_categories() const override; + std::vector get_all_uids() const override; + std::vector get_all_gids() const override; private: template @@ -1766,6 +1768,22 @@ metadata_::get_all_block_categories() const { return rv; } +template +std::vector metadata_::get_all_uids() const { + std::vector rv; + rv.resize(meta_.uids().size()); + std::copy(meta_.uids().begin(), meta_.uids().end(), rv.begin()); + return rv; +} + +template +std::vector metadata_::get_all_gids() const { + std::vector rv; + rv.resize(meta_.gids().size()); + std::copy(meta_.gids().begin(), meta_.gids().end(), rv.begin()); + return rv; +} + std::pair, std::vector> metadata_v2::freeze(const thrift::metadata::metadata& data) { return freeze_to_buffer(data);