From 1299a0d34b15e3dbba2fc0637d04f79a2bc986b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 19 Sep 2023 15:03:28 -0400 Subject: [PATCH] connection manager: cleanup Change-Id: I6a5d7b458f033f0d3dfebefb29bc7a097720e701 --- include/fileutils.h | 13 ------------- src/connectionmanager.cpp | 6 +++--- src/fileutils.cpp | 4 ++-- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/include/fileutils.h b/include/fileutils.h index 7b1cc72..f3bdb5c 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -86,19 +86,6 @@ int remove(const std::filesystem::path& path, bool erase = false); */ int removeAll(const std::filesystem::path& path, bool erase = false); -/** - * Wrappers for fstream opening that will convert paths to wstring - * on windows - */ -void openStream(std::ifstream& file, - const std::filesystem::path& path, - std::ios_base::openmode mode = std::ios_base::in); -void openStream(std::ofstream& file, - const std::filesystem::path& path, - std::ios_base::openmode mode = std::ios_base::out); -std::ifstream ifstream(const std::filesystem::path& path, std::ios_base::openmode mode = std::ios_base::in); -std::ofstream ofstream(const std::filesystem::path& path, std::ios_base::openmode mode = std::ios_base::out); - /** * Windows compatibility wrapper for checking read-only attribute */ diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index 0b97ac5..238f4b4 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -1306,10 +1306,10 @@ ConnectionManager::Impl::dhParams() const template<typename ID = dht::Value::Id> std::set<ID, std::less<>> -loadIdList(const std::string& path) +loadIdList(const std::filesystem::path& path) { std::set<ID, std::less<>> ids; - std::ifstream file = fileutils::ifstream(path); + std::ifstream file(path); if (!file.is_open()) { //JAMI_DBG("Could not load %s", path.c_str()); return ids; @@ -1333,7 +1333,7 @@ template<typename List = std::set<dht::Value::Id>> void saveIdList(const std::filesystem::path& path, const List& ids) { - std::ofstream file = fileutils::ofstream(path, std::ios::trunc | std::ios::binary); + std::ofstream file(path, std::ios::trunc | std::ios::binary); if (!file.is_open()) { //JAMI_ERR("Could not save to %s", path.c_str()); return; diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 7ba5eb8..23aceff 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -153,7 +153,7 @@ std::vector<uint8_t> loadFile(const std::filesystem::path& path) { std::vector<uint8_t> buffer; - std::ifstream file = ifstream(path, std::ios::binary); + std::ifstream file(path, std::ios::binary); if (!file) throw std::runtime_error("Can't read file: " + path.string()); file.seekg(0, std::ios::end); @@ -170,7 +170,7 @@ loadFile(const std::filesystem::path& path) void saveFile(const std::filesystem::path& path, const uint8_t* data, size_t data_size, mode_t mode) { - std::ofstream file = fileutils::ofstream(path, std::ios::trunc | std::ios::binary); + std::ofstream file(path, std::ios::trunc | std::ios::binary); if (!file.is_open()) { //JAMI_ERR("Could not write data to %s", path.c_str()); return; -- GitLab