From 40e43a153f1a41754162f6945412b00d51c6835f Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 23 Aug 2024 16:05:38 +0200 Subject: [PATCH] feat(internal): allow storing "." and ".." in dir_entry_view_impl --- .../dwarfs/reader/internal/metadata_types.h | 50 ++++++++++++------- src/reader/internal/metadata_types.cpp | 49 ++++++++++++------ 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/include/dwarfs/reader/internal/metadata_types.h b/include/dwarfs/reader/internal/metadata_types.h index 89d6499c..08f2d38e 100644 --- a/include/dwarfs/reader/internal/metadata_types.h +++ b/include/dwarfs/reader/internal/metadata_types.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -119,38 +120,49 @@ class dir_entry_view_impl { using DirEntryView = ::apache::thrift::frozen::View; + enum class entry_name_type : uint8_t { + other, + self, + parent, + }; + dir_entry_view_impl(DirEntryView v, uint32_t self_index, - uint32_t parent_index, global_metadata const& g) + uint32_t parent_index, global_metadata const& g, + entry_name_type name_type) : v_{v} , self_index_{self_index} , parent_index_{parent_index} - , g_{&g} {} + , g_{&g, name_type} {} dir_entry_view_impl(InodeView v, uint32_t self_index, uint32_t parent_index, - global_metadata const& g) + global_metadata const& g, entry_name_type name_type) : v_{v} , self_index_{self_index} , parent_index_{parent_index} - , g_{&g} {} + , g_{&g, name_type} {} - static std::shared_ptr - from_dir_entry_index_shared(uint32_t self_index, uint32_t parent_index, - global_metadata const& g); - static std::shared_ptr - from_dir_entry_index_shared(uint32_t self_index, global_metadata const& g); + static std::shared_ptr from_dir_entry_index_shared( + uint32_t self_index, uint32_t parent_index, global_metadata const& g, + entry_name_type name_type = entry_name_type::other); + static std::shared_ptr from_dir_entry_index_shared( + uint32_t self_index, global_metadata const& g, + entry_name_type name_type = entry_name_type::other); static dir_entry_view_impl from_dir_entry_index(uint32_t self_index, uint32_t parent_index, - global_metadata const& g); + global_metadata const& g, + entry_name_type name_type = entry_name_type::other); static dir_entry_view_impl - from_dir_entry_index(uint32_t self_index, global_metadata const& g); + from_dir_entry_index(uint32_t self_index, global_metadata const& g, + entry_name_type name_type = entry_name_type::other); // TODO: this works, but it's strange; a limited version of // dir_entry_view_impl // should work without a parent for these use cases - static std::string name(uint32_t index, global_metadata const& g); + static std::string + name(uint32_t index, global_metadata const& g); // TODO: remove? static std::shared_ptr - inode_shared(uint32_t index, global_metadata const& g); + inode_shared(uint32_t index, global_metadata const& g); // TODO: remove? std::string name() const; std::shared_ptr inode_shared() const; @@ -175,16 +187,18 @@ class dir_entry_view_impl { auto make_inode() const; template