From 1eca4959e7e70f5f0eacd54d14c156be973733dd Mon Sep 17 00:00:00 2001 From: liukunyu Date: Thu, 24 May 2018 15:46:07 +0800 Subject: [PATCH 1/4] fix import_key crash for wallet --- src/filesystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index eb3d685..625f7f2 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -241,7 +241,8 @@ namespace fc { void remove_all( const path& p ) { boost::filesystem::remove_all(p); } void copy( const path& f, const path& t ) { try { - boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); + boost::system::error_code ec; + boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t), ec ); } catch ( boost::system::system_error& e ) { FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${reason}", ("srcfile",f)("dstfile",t)("reason",e.what() ) ); From ce7cb0dd06df4995cefee51ba61c3b690b5d0518 Mon Sep 17 00:00:00 2001 From: BITSG-Jerry Date: Thu, 9 Aug 2018 12:28:42 -0400 Subject: [PATCH 2/4] Check error after called boost::filesystem::copy() and rethrow if found an error. This is to get around boost 1.67 issue https://svn.boost.org/trac10/ticket/13585 --- src/filesystem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 625f7f2..bd98e57 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -243,6 +243,11 @@ namespace fc { try { boost::system::error_code ec; boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t), ec ); + if( ec ) + { + FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${reason}:${value}", + ("srcfile",f)("dstfile",t)("reason",ec.category().name())("value",ec.value()) ); + } } catch ( boost::system::system_error& e ) { FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${reason}", ("srcfile",f)("dstfile",t)("reason",e.what() ) ); From 35cb63d3ead1447e7e6cd3b6e7acedd6a86ae8cf Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 9 Aug 2018 12:57:08 -0400 Subject: [PATCH 3/4] Call FC wrappers of copy and remove in rename() to get around boost 1.67 boost::filesystem::copy() null pointer dereferencing issue --- src/filesystem.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index bd98e57..8185fc3 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -303,13 +303,14 @@ namespace fc { void rename( const path& f, const path& t ) { try { boost::filesystem::rename( boost::filesystem::path(f), boost::filesystem::path(t) ); - } catch ( boost::system::system_error& ) { - try{ - boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); - boost::filesystem::remove( boost::filesystem::path(f)); - } catch ( boost::system::system_error& e ) { - FC_THROW( "Rename from ${srcfile} to ${dstfile} failed because ${reason}", - ("srcfile",f)("dstfile",t)("reason",e.what() ) ); + } catch ( boost::system::system_error& er ) { + try { + copy( f, t ); + remove( f ); + } catch ( fc::exception& e ) { + FC_RETHROW_EXCEPTION( e, error, + "Rename from ${srcfile} to ${dstfile} failed due to ${reason}, trying to copy then remove", + ("srcfile",f)("dstfile",t)("reason",er.what()) ); } } catch ( ... ) { FC_THROW( "Rename from ${srcfile} to ${dstfile} failed", From 64b4bd4900875ee8fe611c7a31a4925cd495fe9e Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 9 Aug 2018 16:31:56 -0400 Subject: [PATCH 4/4] Wrap system_error::what() in a string --- src/filesystem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 8185fc3..5b89102 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -245,12 +245,12 @@ namespace fc { boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t), ec ); if( ec ) { - FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${reason}:${value}", - ("srcfile",f)("dstfile",t)("reason",ec.category().name())("value",ec.value()) ); + FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${code} : ${message}", + ("srcfile",f)("dstfile",t)("code",ec.value())("message",ec.message()) ); } } catch ( boost::system::system_error& e ) { FC_THROW( "Copy from ${srcfile} to ${dstfile} failed because ${reason}", - ("srcfile",f)("dstfile",t)("reason",e.what() ) ); + ("srcfile",f)("dstfile",t)("reason",std::string(e.what()) ) ); } catch ( ... ) { FC_THROW( "Copy from ${srcfile} to ${dstfile} failed", ("srcfile",f)("dstfile",t)("inner", fc::except_str() ) ); @@ -264,7 +264,7 @@ namespace fc { catch ( boost::system::system_error& e ) { FC_THROW( "Resize file '${f}' to size ${s} failed: ${reason}", - ("f",f)("s",t)( "reason", e.what() ) ); + ("f",f)("s",t)( "reason", std::string(e.what()) ) ); } catch ( ... ) { @@ -310,7 +310,7 @@ namespace fc { } catch ( fc::exception& e ) { FC_RETHROW_EXCEPTION( e, error, "Rename from ${srcfile} to ${dstfile} failed due to ${reason}, trying to copy then remove", - ("srcfile",f)("dstfile",t)("reason",er.what()) ); + ("srcfile",f)("dstfile",t)("reason",std::string(er.what())) ); } } catch ( ... ) { FC_THROW( "Rename from ${srcfile} to ${dstfile} failed",