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



commit b00f8f3d92ff08f1dab63d56a3e60f55d81cd9df
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 a66c9cd..d512645 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]