aboutsummaryrefslogtreecommitdiff
path: root/src/common/boost_serialization_helper.h
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-12-20 17:40:11 +0200
committerRiccardo Spagni <ric@spagni.net>2016-12-20 17:40:11 +0200
commitb9b9028e50e647073f55a8f32696ff593bc2fc16 (patch)
tree97376d7c253230f28821ddd9ccb2e3b65df29990 /src/common/boost_serialization_helper.h
parentMerge pull request #1464 (diff)
parentsupport importing unportable outputs (diff)
downloadmonero-b9b9028e50e647073f55a8f32696ff593bc2fc16.tar.xz
Merge pull request #1462
07b9138c support importing unportable outputs (kenshi84) 2ac80075 also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp (kenshi84) d1d6e27a moved boost cpp into hpp since they're supposed to be header only (kenshi84) 66e6af89 added experimental boost::archive::portable_binary_{i|o}archive (kenshi84)
Diffstat (limited to 'src/common/boost_serialization_helper.h')
-rw-r--r--src/common/boost_serialization_helper.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h
index bf0023471..88dccbde7 100644
--- a/src/common/boost_serialization_helper.h
+++ b/src/common/boost_serialization_helper.h
@@ -30,8 +30,9 @@
#pragma once
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
namespace tools
@@ -75,7 +76,7 @@ namespace tools
return false;
#endif
- boost::archive::binary_oarchive a(data_file);
+ boost::archive::portable_binary_oarchive a(data_file);
a << obj;
if (data_file.fail())
return false;
@@ -99,9 +100,23 @@ namespace tools
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;
+ try
+ {
+ // 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();
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
}