mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-14 23:05:33 -04:00
Reimplement path function in entry_view
This commit is contained in:
parent
af1877b7f6
commit
3bb0d7609e
@ -23,7 +23,9 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
@ -152,7 +154,10 @@ class dir_entry_view {
|
|||||||
std::optional<dir_entry_view> parent() const;
|
std::optional<dir_entry_view> parent() const;
|
||||||
|
|
||||||
std::string path() 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_; }
|
uint32_t self_index() const { return self_index_; }
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "dwarfs/logger.h"
|
#include "dwarfs/logger.h"
|
||||||
#include "dwarfs/metadata_types.h"
|
#include "dwarfs/metadata_types.h"
|
||||||
#include "dwarfs/overloaded.h"
|
#include "dwarfs/overloaded.h"
|
||||||
|
#include "dwarfs/util.h"
|
||||||
|
|
||||||
#include "dwarfs/gen-cpp2/metadata_types_custom_protocol.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 dir_entry_view::path() const {
|
||||||
std::string p;
|
return u8string_to_string(fs_path().u8string());
|
||||||
append_path_to(p);
|
}
|
||||||
|
|
||||||
|
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;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_entry_view::append_path_to(std::string& s) const {
|
void dir_entry_view::append_to(std::filesystem::path& p) const {
|
||||||
if (auto p = parent()) {
|
if (auto ev = parent()) {
|
||||||
if (!p->is_root()) {
|
if (!ev->is_root()) {
|
||||||
p->append_path_to(s);
|
ev->append_to(p);
|
||||||
s += '/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!is_root()) {
|
if (!is_root()) {
|
||||||
s += name();
|
p /= string_to_u8string(name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user