From a0f51660f506dd8ce224624ba3d15c298e016dcd Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 26 Jun 2023 21:32:33 +0200 Subject: [PATCH] Add unix_path() to entry_view --- include/dwarfs/metadata_types.h | 1 + src/dwarfs/metadata_types.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/dwarfs/metadata_types.h b/include/dwarfs/metadata_types.h index 0f7b0cfa..3c791e3c 100644 --- a/include/dwarfs/metadata_types.h +++ b/include/dwarfs/metadata_types.h @@ -160,6 +160,7 @@ class dir_entry_view { std::optional parent() const; std::string path() const; + std::string unix_path() const; std::filesystem::path fs_path() const; std::wstring wpath() const; diff --git a/src/dwarfs/metadata_types.cpp b/src/dwarfs/metadata_types.cpp index fdcf01a0..087ae460 100644 --- a/src/dwarfs/metadata_types.cpp +++ b/src/dwarfs/metadata_types.cpp @@ -668,6 +668,18 @@ std::string dir_entry_view::path() const { return u8string_to_string(fs_path().u8string()); } +std::string dir_entry_view::unix_path() const { +#ifdef _WIN32 + auto p = fs_path().u8string(); + std::replace(p.begin(), p.end(), + static_cast(std::filesystem::path::preferred_separator), + '/'); + return u8string_to_string(p); +#else + return path(); +#endif +} + std::wstring dir_entry_view::wpath() const { return fs_path().wstring(); } std::filesystem::path dir_entry_view::fs_path() const {