Skip to content

Commit

Permalink
Support boost filesystem copy_options (newer boost version).
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFFFC0000 committed Apr 26, 2024
1 parent c821478 commit 38615b4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
2 changes: 2 additions & 0 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/p2p/net_peerlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <boost/serialization/version.hpp>

#include "net_peerlist_boost_serialization.h"
#include "common/util.h"


namespace nodetool
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) copy_file(m_wallet_file, m_wallet_file + ".unportable");
std::stringstream iss;
iss.str("");
iss << cache_file_buf;
Expand Down
3 changes: 2 additions & 1 deletion tests/core_tests/chaingen_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/filesystem/operations.hpp>

#include "common/util.h"

namespace tools
{
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 38615b4

Please sign in to comment.