mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp
This commit is contained in:
parent
d1d6e27ab6
commit
2ac8007544
7 changed files with 50 additions and 19 deletions
|
@ -30,8 +30,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
#include <boost/archive/binary_iarchive.hpp>
|
||||||
|
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||||
|
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace tools
|
namespace tools
|
||||||
|
@ -76,7 +77,7 @@ namespace tools
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::archive::binary_oarchive a(data_file);
|
boost::archive::portable_binary_oarchive a(data_file);
|
||||||
a << obj;
|
a << obj;
|
||||||
if (data_file.fail())
|
if (data_file.fail())
|
||||||
return false;
|
return false;
|
||||||
|
@ -101,9 +102,23 @@ namespace tools
|
||||||
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
|
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
|
||||||
if(data_file.fail())
|
if(data_file.fail())
|
||||||
return false;
|
return false;
|
||||||
boost::archive::binary_iarchive a(data_file);
|
try
|
||||||
|
{
|
||||||
a >> obj;
|
// first try reading in portable mode
|
||||||
|
boost::archive::portable_binary_iarchive a(data_file);
|
||||||
|
a >> obj;
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
// if failed, try reading in unportable mode
|
||||||
|
boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||||
|
data_file.close();
|
||||||
|
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
|
||||||
|
if(data_file.fail())
|
||||||
|
return false;
|
||||||
|
boost::archive::binary_iarchive a(data_file);
|
||||||
|
a >> obj;
|
||||||
|
}
|
||||||
return !data_file.fail();
|
return !data_file.fail();
|
||||||
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
|
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
//
|
//
|
||||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
#include <boost/archive/binary_iarchive.hpp>
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/portable_binary_iarchive.hpp>
|
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||||
#include <boost/archive/portable_binary_oarchive.hpp>
|
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||||
#include "cryptonote_basic.h"
|
#include "cryptonote_basic.h"
|
||||||
|
|
|
@ -137,14 +137,34 @@ namespace nodetool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::archive::binary_iarchive a(p2p_data);
|
// first try reading in portable mode
|
||||||
|
boost::archive::portable_binary_iarchive a(p2p_data);
|
||||||
a >> *this;
|
a >> *this;
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (...)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to load p2p config file, falling back to default config");
|
// if failed, try reading in unportable mode
|
||||||
m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
|
boost::filesystem::copy_file(state_file_path, state_file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||||
make_default_config();
|
p2p_data.close();
|
||||||
|
p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::in);
|
||||||
|
if(!p2p_data.fail())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::archive::binary_iarchive a(p2p_data);
|
||||||
|
a >> *this;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Failed to load p2p config file, falling back to default config");
|
||||||
|
m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
|
||||||
|
make_default_config();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
make_default_config();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
|
@ -645,7 +665,7 @@ namespace nodetool
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::archive::binary_oarchive a(p2p_data);
|
boost::archive::portable_binary_oarchive a(p2p_data);
|
||||||
a << *this;
|
a << *this;
|
||||||
return true;
|
return true;
|
||||||
CATCH_ENTRY_L0("blockchain_storage::save", false);
|
CATCH_ENTRY_L0("blockchain_storage::save", false);
|
||||||
|
|
|
@ -36,8 +36,9 @@
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
//#include <boost/bimap.hpp>
|
//#include <boost/bimap.hpp>
|
||||||
//#include <boost/bimap/multiset_of.hpp>
|
//#include <boost/bimap/multiset_of.hpp>
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
#include <boost/archive/binary_iarchive.hpp>
|
||||||
|
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||||
|
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||||
#include <boost/serialization/version.hpp>
|
#include <boost/serialization/version.hpp>
|
||||||
|
|
||||||
#include <boost/multi_index_container.hpp>
|
#include <boost/multi_index_container.hpp>
|
||||||
|
|
|
@ -2318,7 +2318,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
||||||
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".old", boost::filesystem::copy_option::overwrite_if_exists);
|
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||||
iss.str("");
|
iss.str("");
|
||||||
iss << cache_data;
|
iss << cache_data;
|
||||||
boost::archive::binary_iarchive ar(iss);
|
boost::archive::binary_iarchive ar(iss);
|
||||||
|
@ -2337,7 +2337,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
||||||
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".old", boost::filesystem::copy_option::overwrite_if_exists);
|
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||||
iss.str("");
|
iss.str("");
|
||||||
iss << buf;
|
iss << buf;
|
||||||
boost::archive::binary_iarchive ar(iss);
|
boost::archive::binary_iarchive ar(iss);
|
||||||
|
|
Loading…
Reference in a new issue