Merge pull request #19 from pch957/patch1

filesystem::rename() can handle file from cross device
This commit is contained in:
Daniel Larimer 2014-03-20 00:00:47 -04:00
commit b358b641d4

View file

@ -233,9 +233,14 @@ namespace fc {
void rename( const path& f, const path& t ) { void rename( const path& f, const path& t ) {
try { try {
boost::filesystem::rename( boost::filesystem::path(f), boost::filesystem::path(t) ); boost::filesystem::rename( boost::filesystem::path(f), boost::filesystem::path(t) );
} catch ( boost::system::system_error& e ) {
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 ) { } catch ( boost::system::system_error& e ) {
FC_THROW( "Rename from ${srcfile} to ${dstfile} failed because ${reason}", FC_THROW( "Rename from ${srcfile} to ${dstfile} failed because ${reason}",
("srcfile",f)("dstfile",t)("reason",e.what() ) ); ("srcfile",f)("dstfile",t)("reason",e.what() ) );
}
} catch ( ... ) { } catch ( ... ) {
FC_THROW( "Rename from ${srcfile} to ${dstfile} failed", FC_THROW( "Rename from ${srcfile} to ${dstfile} failed",
("srcfile",f)("dstfile",t)("inner", fc::except_str() ) ); ("srcfile",f)("dstfile",t)("inner", fc::except_str() ) );