[gparted/psusi/refactor: 14/19] Don't revert more than needed



commit b4fde6fb3dd55bf17111d191452418258932af32
Author: Phillip Susi <psusi ubuntu com>
Date:   Sat Jan 26 23:28:33 2013 -0500

    Don't revert more than needed
    
    After a move is canceled or fails, an attempt is made to revert the disk to
    its previous state.  This was moving back all blocks that had already been
    copied.  Many of the first blocks copied during a move do not overwrite
    any valid data, and so do not need put back after an error, so don't bother
    doing so.

 src/GParted_Core.cc |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 031219d..c169cb2 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2813,13 +2813,20 @@ void GParted_Core::rollback_transaction( const Partition & partition_src,
 
 		if ( partition_dst .sector_start > partition_src .sector_start )
 		{
-			temp_src .sector_start = temp_src .sector_end - ( (total_done / temp_src .sector_size) - 1 ) ;
-			temp_dst .sector_start = temp_dst .sector_end - ( (total_done / temp_dst .sector_size) - 1 ) ;
+			Sector distance = partition_dst.sector_start - partition_src.sector_start;
+			temp_src.sector_start = temp_src.sector_end - ( (total_done / temp_src.sector_size) - 1 ) + distance;
+			temp_dst.sector_start = temp_dst.sector_end - ( (total_done / temp_dst.sector_size) - 1 ) + distance;
+			if (temp_src.sector_start > temp_src.sector_end)
+				return;  /* nothing has been overwritten yet, so nothing to roll back */
+
 		}
 		else
 		{
-			temp_src .sector_end = temp_src .sector_start + ( (total_done / temp_src .sector_size) - 1 ) ;
-			temp_dst .sector_end = temp_dst .sector_start + ( (total_done / temp_dst .sector_size) - 1 ) ;
+			Sector distance = partition_src.sector_start - partition_dst.sector_start;
+			temp_src.sector_end = temp_src.sector_start + ( (total_done / temp_src.sector_size) - 1 ) - distance;
+			temp_dst.sector_end = temp_dst.sector_start + ( (total_done / temp_dst.sector_size) - 1 ) - distance;
+			if (temp_src.sector_start > temp_src.sector_end)
+				return;  /* nothing has been overwritten yet, so nothing to roll back */
 		}
 		operationdetail.add_child( OperationDetail( _("roll back last transaction") ) );
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]