[gparted] Refactor resize() to make it even easier to understand (#741211)



commit 95ff4fbdc904889f1c593ad5bfecff7776a90618
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Dec 7 11:08:56 2014 +0000

    Refactor resize() to make it even easier to understand (#741211)
    
    Split the resizing file system and resizing partition calls in
    GParted_Core::resize() into separate grow and shrink code paths.
    
    Note that this also changes the degenerative case of calling resize()
    when the partition isn't changing size, for non-swap partitions, from a
    file system check step to a successful no-op.  This doesn't matter as my
    testing never found resize() to be called when the partition isn't
    changing size.
    
    Also correct spelling of local variable success.
    
    Bug 741211 - Remove unnecessary duplicate actions when resizing a
                 partition

 src/GParted_Core.cc |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index f1f9e69..3477460 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2388,33 +2388,31 @@ bool GParted_Core::resize( const Partition & partition_old,
                return false ;
        }
 
-       bool succes = false ;
+       bool success = true;
        if ( partition_new.filesystem == FS_LINUX_SWAP )
        {
                // linux-swap is recreated, not resize
-               succes =    resize_move_partition( partition_old, partition_new, operationdetail )
-                        && resize_filesystem( partition_old, partition_new, operationdetail );
+               success =    resize_move_partition( partition_old, partition_new, operationdetail )
+                         && resize_filesystem( partition_old, partition_new, operationdetail );
 
-               return succes;
+               return success;
        }
-       else if ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail ) )
-       {
-               succes = true ;
-
-               if ( succes && partition_new .get_sector_length() < partition_old .get_sector_length() )
-                       succes = resize_filesystem( partition_old, partition_new, operationdetail ) ;
-
-               if ( succes )
-                       succes = resize_move_partition( partition_old, partition_new, operationdetail ) ;
-
-               // Maximize file system if growing
-               if ( succes && partition_new .get_sector_length() > partition_old .get_sector_length() )
-                       succes = maximize_filesystem( partition_new, operationdetail );
 
-               return succes ;
+       Sector delta = partition_new.get_sector_length() - partition_old.get_sector_length();
+       if ( delta < 0LL )  // shrink
+       {
+               success =    ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail 
) )
+                         && resize_filesystem( partition_old, partition_new, operationdetail )
+                         && resize_move_partition( partition_old, partition_new, operationdetail );
+       }
+       else if ( delta > 0LL )  // grow
+       {
+               success =    ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail 
) )
+                         && resize_move_partition( partition_old, partition_new, operationdetail )
+                         && maximize_filesystem( partition_new, operationdetail );
        }
 
-       return false ;
+       return success;
 }
 
 bool GParted_Core::resize_move_partition( const Partition & partition_old,


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