From 9702ba83ee82e52a698f1568ae6aef35b17c81a9 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 8 Nov 2026 12:18:17 -0500 Subject: [PATCH] always pass std::filesystem::path to filesystem functions --- daemon/Daemon.cpp | 3 +-- daemon/HTTPServer.cpp | 11 ++++++----- daemon/I2PControl.cpp | 2 +- libi2pd/FS.cpp | 10 +++------- libi2pd/FS.h | 13 +++---------- libi2pd/Garlic.cpp | 8 ++++---- libi2pd/NetDb.cpp | 2 +- libi2pd/Profiling.cpp | 11 ++++++----- libi2pd_client/AddressBook.cpp | 4 ++-- libi2pd_client/ClientContext.cpp | 4 ++-- 10 files changed, 29 insertions(+), 39 deletions(-) diff --git a/daemon/Daemon.cpp b/daemon/Daemon.cpp index 1cef5e2c..f8ae5f38 100644 --- a/daemon/Daemon.cpp +++ b/daemon/Daemon.cpp @@ -98,10 +98,9 @@ namespace util if (config == "") { config = i2p::fs::DataDirPath("i2pd.conf").string (); - if (!i2p::fs::Exists (config)) { + if (!std::filesystem::exists (config)) // use i2pd.conf only if exists config = ""; /* reset */ - } } i2p::config::ParseConfig(config); diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 5fffb4c1..6900fecc 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -48,15 +48,16 @@ namespace http { static void LoadExtCSS (std::string fileName = "style") { - std::stringstream s; - std::string styleFile = i2p::fs::DataDirPath ("webconsole/"+fileName+".css").string (); - if (i2p::fs::Exists(styleFile)) { + auto styleFile = i2p::fs::DataDirPath ("webconsole", fileName + ".css"); + if (std::filesystem::exists(styleFile)) + { + std::stringstream s; std::ifstream f(styleFile, std::ifstream::binary); s << f.rdbuf(); externalCSS = s.str(); - } else if (externalCSS.length() != 0) { // clean up external style if file was removed - externalCSS = ""; } + else if (!externalCSS.empty ()) // clean up external style if file was removed + externalCSS = ""; } static void GetStyles (std::stringstream& s) diff --git a/daemon/I2PControl.cpp b/daemon/I2PControl.cpp index 78e303a0..c8f52967 100644 --- a/daemon/I2PControl.cpp +++ b/daemon/I2PControl.cpp @@ -61,7 +61,7 @@ namespace client i2pcp_crt = i2p::fs::DataDirPath(i2pcp_crt).string (); if (!i2pcp_key.empty () && i2pcp_key[0] != '/') i2pcp_key = i2p::fs::DataDirPath(i2pcp_key).string (); - if (!i2p::fs::Exists (i2pcp_crt) || !i2p::fs::Exists (i2pcp_key)) + if (!std::filesystem::exists (i2pcp_crt) || !std::filesystem::exists (i2pcp_key)) { LogPrint (eLogInfo, "I2PControl: Creating new certificate for control connection ", i2pcp_crt, " key ", i2pcp_key); CreateCertificate (i2pcp_crt.c_str(), i2pcp_key.c_str()); diff --git a/libi2pd/FS.cpp b/libi2pd/FS.cpp index 5b1701e6..63772769 100644 --- a/libi2pd/FS.cpp +++ b/libi2pd/FS.cpp @@ -225,11 +225,7 @@ namespace fs return true; } - bool Exists(const std::string & path) { - return std::filesystem::exists(path); - } - - uint32_t GetLastUpdateTime (const std::string & path) + uint32_t GetLastUpdateTime (const std::filesystem::path& path) { if (!std::filesystem::exists(path)) return 0; @@ -246,7 +242,7 @@ namespace fs return std::chrono::system_clock::to_time_t(sctp); } - bool Remove(const std::string & path) + bool Remove(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) return false; @@ -267,7 +263,7 @@ namespace fs return true; } - bool CreateDirectory (const std::string& path) + bool CreateDirectory (const std::filesystem::path& path) { if (std::filesystem::exists(path) && std::filesystem::is_directory (std::filesystem::status (path))) return true; diff --git a/libi2pd/FS.h b/libi2pd/FS.h index c655d290..e6ba86ff 100644 --- a/libi2pd/FS.h +++ b/libi2pd/FS.h @@ -129,20 +129,13 @@ namespace fs * @param path Absolute path to file * @return true on success, false if file not exists, throws exception on error */ - bool Remove(const std::string & path); + bool Remove (const std::filesystem::path& path); bool Rename (std::string_view from, std::string_view to); - /** - * @brief Check existence of file - * @param path Absolute path to file - * @return true if file exists, false otherwise - */ - bool Exists(const std::string & path); + uint32_t GetLastUpdateTime (const std::filesystem::path& path); // seconds since epoch - uint32_t GetLastUpdateTime (const std::string & path); // seconds since epoch - - bool CreateDirectory (const std::string& path); + bool CreateDirectory (const std::filesystem::path& path); std::filesystem::path CreatePrivateFile (const std::filesystem::path& path); /** diff --git a/libi2pd/Garlic.cpp b/libi2pd/Garlic.cpp index fe2ad973..49a0876f 100644 --- a/libi2pd/Garlic.cpp +++ b/libi2pd/Garlic.cpp @@ -975,7 +975,7 @@ namespace garlic std::string ident = GetIdentHash().ToBase32(); auto path = i2p::fs::DataDirPath("tags", (ident + ".tags")); uint32_t ts = i2p::util::GetSecondsSinceEpoch (); - if (ts < i2p::fs::GetLastUpdateTime (path.string ()) + INCOMING_TAGS_EXPIRATION_TIMEOUT) + if (ts < i2p::fs::GetLastUpdateTime (path) + INCOMING_TAGS_EXPIRATION_TIMEOUT) { // might contain non-expired tags std::ifstream f (path, std::ifstream::binary); @@ -1009,7 +1009,7 @@ namespace garlic LogPrint (eLogInfo, "Garlic: ", m_Tags.size (), " tags loaded for ", ident); } } - i2p::fs::Remove (path.string ()); + i2p::fs::Remove (path); } void CleanUpTagsFiles () @@ -1018,8 +1018,8 @@ namespace garlic i2p::fs::ReadDir (i2p::fs::DataDirPath("tags"), files); uint32_t ts = i2p::util::GetSecondsSinceEpoch (); for (auto it: files) - if (ts >= i2p::fs::GetLastUpdateTime (it.string ()) + INCOMING_TAGS_EXPIRATION_TIMEOUT) - i2p::fs::Remove (it.string ()); + if (ts >= i2p::fs::GetLastUpdateTime (it) + INCOMING_TAGS_EXPIRATION_TIMEOUT) + i2p::fs::Remove (it); } void GarlicDestination::HandleECIESx25519GarlicClove (const uint8_t * buf, size_t len, diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 2f807323..93043557 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -548,7 +548,7 @@ namespace data else { LogPrint(eLogWarning, "NetDb: RI from ", p, " is invalid or too old. Delete"); - i2p::fs::Remove(p.string ()); // TODO: + i2p::fs::Remove(p); } return true; } diff --git a/libi2pd/Profiling.cpp b/libi2pd/Profiling.cpp index 9cd5c81a..95efde65 100644 --- a/libi2pd/Profiling.cpp +++ b/libi2pd/Profiling.cpp @@ -89,10 +89,10 @@ namespace data { m_IsUpdated = false; std::string ident = identHash.ToBase64 (); - std::string path = g_ProfilesStorage.Path(ident).string (); + auto path = g_ProfilesStorage.Path(ident); boost::property_tree::ptree pt; - if (!i2p::fs::Exists(path)) + if (!std::filesystem::exists(path)) { LogPrint(eLogWarning, "Profiling: No profile yet for ", ident); return; @@ -100,8 +100,9 @@ namespace data try { - boost::property_tree::read_ini (path, pt, std::locale::classic()); - } catch (std::exception& ex) + boost::property_tree::read_ini (path.string (), pt, std::locale::classic()); + } + catch (std::exception& ex) { /* boost exception verbose enough */ LogPrint (eLogError, "Profiling: ", ex.what ()); @@ -366,7 +367,7 @@ namespace data if (now - st.st_mtime >= PEER_PROFILE_EXPIRATION_TIMEOUT) { LogPrint(eLogDebug, "Profiling: Removing expired peer profile: ", path); - i2p::fs::Remove(path.string ()); + i2p::fs::Remove(path); } } } diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index d71043ec..019b677f 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -81,8 +81,8 @@ namespace client { // init ETags etagsPath = i2p::fs::StorageRootPath (storage, "etags"); - if (!i2p::fs::Exists (etagsPath.string ())) - i2p::fs::CreateDirectory (etagsPath.string ()); + if (!std::filesystem::exists (etagsPath)) + i2p::fs::CreateDirectory (etagsPath); // init address files indexPath = i2p::fs::StorageRootPath (storage, "addresses.csv"); localPath = i2p::fs::StorageRootPath (storage, "local.csv"); diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index 43015469..94587d00 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -595,7 +595,7 @@ namespace client if (tunConf.empty ()) tunConf = i2p::fs::DataDirPath ("tunnels.conf").string (); - if (i2p::fs::Exists (tunConf)) + if (std::filesystem::exists (tunConf)) { LogPrint(eLogDebug, "Clients: Tunnels config file: ", tunConf); ReadTunnels (tunConf, numClientTunnels, numServerTunnels); @@ -605,7 +605,7 @@ namespace client if (tunDir.empty ()) tunDir = i2p::fs::DataDirPath ("tunnels.d").string (); - if (i2p::fs::Exists (tunDir)) + if (std::filesystem::exists (tunDir)) { std::vector files; if (i2p::fs::ReadDir (tunDir, files))