mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-11-14 15:17:34 +00:00
use std::filesystem::path for file path
This commit is contained in:
1 parent
67cd6a0848
commit
bc849eafd6
2 files changed
+13
-12
No files matched your search
@@ -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<Buffer> buf)
|
||||
bool RouterInfo::SaveToFile (const std::filesystem::path& fullPath, std::shared_ptr<Buffer> 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)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include <utility> // for C++20 with boost < 1.81
|
||||
#include <boost/asio.hpp>
|
||||
#ifndef __cpp_lib_atomic_shared_ptr
|
||||
@@ -219,7 +220,7 @@ namespace data
|
||||
#else
|
||||
typedef boost::shared_ptr<Addresses> 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<Buffer>&& 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<Buffer> 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<Buffer> buf);
|
||||
bool SaveToFile (const std::filesystem::path& fullPath);
|
||||
static bool SaveToFile (const std::filesystem::path& fullPath, std::shared_ptr<Buffer> buf);
|
||||
|
||||
std::shared_ptr<RouterProfile> 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;
|
||||
|
||||
Reference in new issue
Block a user