From 3bb0d7609ed67b934ccc73e05d1311792d95bc8f Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 26 Jun 2023 18:41:09 +0200 Subject: [PATCH] Reimplement path function in entry_view --- include/dwarfs/metadata_types.h | 7 ++++++- src/dwarfs/metadata_types.cpp | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/dwarfs/metadata_types.h b/include/dwarfs/metadata_types.h index dbb2d06c..e692d4f0 100644 --- a/include/dwarfs/metadata_types.h +++ b/include/dwarfs/metadata_types.h @@ -23,7 +23,9 @@ #include #include +#include #include +#include #include #include @@ -152,7 +154,10 @@ class dir_entry_view { std::optional parent() const; std::string path() const; - void append_path_to(std::string& s) const; + std::filesystem::path fs_path() const; + std::wstring wpath() const; + + void append_to(std::filesystem::path& p) const; uint32_t self_index() const { return self_index_; } diff --git a/src/dwarfs/metadata_types.cpp b/src/dwarfs/metadata_types.cpp index 20f45102..fdcf01a0 100644 --- a/src/dwarfs/metadata_types.cpp +++ b/src/dwarfs/metadata_types.cpp @@ -29,6 +29,7 @@ #include "dwarfs/logger.h" #include "dwarfs/metadata_types.h" #include "dwarfs/overloaded.h" +#include "dwarfs/util.h" #include "dwarfs/gen-cpp2/metadata_types_custom_protocol.h" @@ -664,20 +665,25 @@ inode_view dir_entry_view::inode(uint32_t index, global_metadata const* g) { } std::string dir_entry_view::path() const { - std::string p; - append_path_to(p); + return u8string_to_string(fs_path().u8string()); +} + +std::wstring dir_entry_view::wpath() const { return fs_path().wstring(); } + +std::filesystem::path dir_entry_view::fs_path() const { + std::filesystem::path p; + append_to(p); return p; } -void dir_entry_view::append_path_to(std::string& s) const { - if (auto p = parent()) { - if (!p->is_root()) { - p->append_path_to(s); - s += '/'; +void dir_entry_view::append_to(std::filesystem::path& p) const { + if (auto ev = parent()) { + if (!ev->is_root()) { + ev->append_to(p); } } if (!is_root()) { - s += name(); + p /= string_to_u8string(name()); } }