From 7506790bee4b7eb9ae1fbc199bea33c0631f53b5 Mon Sep 17 00:00:00 2001 From: alt Date: Thu, 20 Mar 2014 09:27:32 +0800 Subject: [PATCH] filesystem::rename() can handle file from cross device --- src/filesystem.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 537706f..a95aae7 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -234,8 +234,13 @@ namespace fc { try { boost::filesystem::rename( boost::filesystem::path(f), boost::filesystem::path(t) ); } catch ( boost::system::system_error& e ) { - FC_THROW( "Rename from ${srcfile} to ${dstfile} failed because ${reason}", - ("srcfile",f)("dstfile",t)("reason",e.what() ) ); + 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 ( ... ) { FC_THROW( "Rename from ${srcfile} to ${dstfile} failed", ("srcfile",f)("dstfile",t)("inner", fc::except_str() ) );