diff options
author | 0xFFFC0000 <0xFFFC0000@proton.me> | 2024-04-30 23:20:10 +0000 |
---|---|---|
committer | 0xFFFC0000 <0xFFFC0000@proton.me> | 2024-04-30 23:20:10 +0000 |
commit | de9c461a98f5e1fe3d428222f4917991a74c4b8f (patch) | |
tree | d99a457d423670f7e080243bfd802ef0a713df9f /src | |
parent | Merge pull request #9243 (diff) | |
download | monero-de9c461a98f5e1fe3d428222f4917991a74c4b8f.tar.xz |
common: support boost filesystem copy_options.
Co-authored-by: selsta <selsta@sent.at>
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.cpp | 18 | ||||
-rw-r--r-- | src/common/util.h | 2 | ||||
-rw-r--r-- | src/p2p/net_peerlist.cpp | 3 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 4 |
4 files changed, 24 insertions, 3 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp index b4f3360ef..e84348a00 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -114,6 +114,24 @@ static int flock_exnb(int fd) namespace tools { + + void copy_file(const std::string& from, const std::string& to) + { + using boost::filesystem::path; + #if BOOST_VERSION < 107400 + // Remove this preprocessor if/else when we are bumping the boost version. + boost::filesystem::copy_file( + path(from), + path(to), + boost::filesystem::copy_option::overwrite_if_exists); + #else + boost::filesystem::copy_file( + path(from), + path(to), + boost::filesystem::copy_options::overwrite_existing); + #endif + } + std::function<void(int)> signal_handler::m_handler; private_file::private_file() noexcept : m_handle(), m_filename() {} diff --git a/src/common/util.h b/src/common/util.h index 05748e020..3c42c8605 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -67,6 +67,8 @@ namespace tools } }; + void copy_file(const std::string& from, const std::string& to); + //! A file restricted to process owner AND process. Deletes file on destruction. class private_file { std::unique_ptr<std::FILE, close_file> m_handle; diff --git a/src/p2p/net_peerlist.cpp b/src/p2p/net_peerlist.cpp index 11cf235a5..78cf13785 100644 --- a/src/p2p/net_peerlist.cpp +++ b/src/p2p/net_peerlist.cpp @@ -42,6 +42,7 @@ #include <boost/serialization/version.hpp> #include "net_peerlist_boost_serialization.h" +#include "common/util.h" namespace nodetool @@ -200,7 +201,7 @@ namespace nodetool if (!out) { // if failed, try reading in unportable mode - boost::filesystem::copy_file(path, path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(path, path + ".unportable"); src_file.close(); src_file.open( path , std::ios_base::binary | std::ios_base::in); if(src_file.fail()) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a9ad67f04..bdf5c6b69 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -6136,7 +6136,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass catch (...) { LOG_PRINT_L0("Failed to open portable binary, trying unportable"); - if (use_fs) boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + if (use_fs) tools::copy_file(m_wallet_file, m_wallet_file + ".unportable"); std::stringstream iss; iss.str(""); iss << cache_data; @@ -6158,7 +6158,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass catch (...) { LOG_PRINT_L0("Failed to open portable binary, trying unportable"); - if (use_fs) boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + if (use_fs) tools::copy_file(m_wallet_file, m_wallet_file + ".unportable"); std::stringstream iss; iss.str(""); iss << cache_file_buf; |