From bc849eafd6a4eded3e48dec88a7fb939f1814ae8 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 7 Nov 2026 14:50:00 -0500 Subject: [PATCH] use std::filesystem::path for file path --- libi2pd/RouterInfo.cpp | 12 ++++++------ libi2pd/RouterInfo.h | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index b61b069d..9e899657 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -44,7 +44,7 @@ namespace data m_Addresses = AddressesPtr(new Addresses ()); // create empty list } - RouterInfo::RouterInfo (const std::string& fullPath): + RouterInfo::RouterInfo (const std::filesystem::path& fullPath): m_FamilyID (0), m_IsUpdated (false), m_IsUnreachable (false), m_IsFloodfill (false), m_IsBufferScheduledToDelete (false), m_SupportedTransports (0), m_ReachableTransports (0), m_PublishedTransports (0), m_Caps (0), m_Version (0), @@ -126,7 +126,7 @@ namespace data m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); } - bool RouterInfo::LoadFile (const std::string& fullPath) + bool RouterInfo::LoadFile (const std::filesystem::path& fullPath) { std::ifstream s(fullPath, std::ifstream::binary); if (s.is_open ()) @@ -152,7 +152,7 @@ namespace data return true; } - void RouterInfo::ReadFromFile (const std::string& fullPath) + void RouterInfo::ReadFromFile (const std::filesystem::path& fullPath) { if (LoadFile (fullPath)) ReadFromBuffer (false); @@ -606,7 +606,7 @@ namespace data return bufbe64toh (buf + size) > m_Timestamp; } - const uint8_t * RouterInfo::LoadBuffer (const std::string& fullPath) + const uint8_t * RouterInfo::LoadBuffer (const std::filesystem::path& fullPath) { if (!m_Buffer) { @@ -618,7 +618,7 @@ namespace data return m_Buffer->data (); } - bool RouterInfo::SaveToFile (const std::string& fullPath, std::shared_ptr buf) + bool RouterInfo::SaveToFile (const std::filesystem::path& fullPath, std::shared_ptr buf) { if (!buf) return false; std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out); @@ -631,7 +631,7 @@ namespace data return true; } - bool RouterInfo::SaveToFile (const std::string& fullPath) + bool RouterInfo::SaveToFile (const std::filesystem::path& fullPath) { if (m_IsUnreachable) return false; // don't save bad router if (!m_Buffer) diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index c67c0d3e..a32ccc73 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -18,6 +18,7 @@ #include #include #include +#include #include // for C++20 with boost < 1.81 #include #ifndef __cpp_lib_atomic_shared_ptr @@ -219,7 +220,7 @@ namespace data #else typedef boost::shared_ptr AddressesPtr; #endif - RouterInfo (const std::string& fullPath); + RouterInfo (const std::filesystem::path& fullPath); RouterInfo (const RouterInfo& ) = delete; RouterInfo& operator=(const RouterInfo& ) = delete; RouterInfo (std::shared_ptr&& buf, size_t len); @@ -301,7 +302,7 @@ namespace data void ExcludeReachableTransports (CompatibleTransports transports) { m_ReachableTransports &= ~transports; }; const uint8_t * GetBuffer () const { return m_Buffer ? m_Buffer->data () : nullptr; }; - const uint8_t * LoadBuffer (const std::string& fullPath); // load if necessary + const uint8_t * LoadBuffer (const std::filesystem::path& fullPath); // load if necessary size_t GetBufferLen () const { return m_Buffer ? m_Buffer->GetBufferLen () : 0; }; void DeleteBuffer () { m_Buffer = nullptr; m_IsBufferScheduledToDelete = false; }; std::shared_ptr GetSharedBuffer () const { return m_Buffer; }; @@ -312,8 +313,8 @@ namespace data bool IsUpdated () const { return m_IsUpdated; }; void SetUpdated (bool updated) { m_IsUpdated = updated; }; - bool SaveToFile (const std::string& fullPath); - static bool SaveToFile (const std::string& fullPath, std::shared_ptr buf); + bool SaveToFile (const std::filesystem::path& fullPath); + static bool SaveToFile (const std::filesystem::path& fullPath, std::shared_ptr buf); std::shared_ptr GetProfile () const; void DropProfile () { m_Profile = nullptr; }; @@ -345,8 +346,8 @@ namespace data private: - bool LoadFile (const std::string& fullPath); - void ReadFromFile (const std::string& fullPath); + bool LoadFile (const std::filesystem::path& fullPath); + void ReadFromFile (const std::filesystem::path& fullPath); bool ReadFromBuffer (const uint8_t * buf, size_t len); // return false if malformed void ReadFromBuffer (bool verifySignature); std::string_view ExtractString (const uint8_t * buf, size_t len) const;