diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2024-05-20 23:39:01 -0500 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2024-05-20 23:39:01 -0500 |
| commit | b13e597e8e347b26055047e417963650d9bd7f1f (patch) | |
| tree | 17ff180801624c8d630c4f9734c22f93479778a1 /src/common | |
| parent | 19fa7dceac6de9a2c8c5f6231284a26a5bc60ed0 (diff) | |
| parent | 755dddd2bc9a74fe7f2a61fc49af2a98ca4e82ee (diff) | |
| download | monzero-core-b13e597e8e347b26055047e417963650d9bd7f1f.tar.gz monzero-core-b13e597e8e347b26055047e417963650d9bd7f1f.tar.xz monzero-core-b13e597e8e347b26055047e417963650d9bd7f1f.zip | |
Merge pull request #9306
755dddd common: support boost filesystem copy_options. Co-authored-by: selsta <selsta@sent.at> (0xFFFC0000)
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/boost_serialization_helper.h | 3 | ||||
| -rw-r--r-- | src/common/util.cpp | 18 | ||||
| -rw-r--r-- | src/common/util.h | 2 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index 4a903107f..1eca39f40 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -35,6 +35,7 @@ #include <boost/archive/portable_binary_iarchive.hpp> #include <boost/filesystem/operations.hpp> +#include "common/util.h" namespace tools { @@ -110,7 +111,7 @@ namespace tools catch(...) { // if failed, try reading in unportable mode - boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(file_path, file_path + ".unportable"); data_file.close(); data_file.open( file_path, std::ios_base::binary | std::ios_base::in); if(data_file.fail()) diff --git a/src/common/util.cpp b/src/common/util.cpp index 829f4605c..a60c79d3a 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -115,6 +115,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 35b897017..9f21b259f 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; |
