[gparted] Extract common code into update_dmraid_entry() (#791875)



commit 93ccc79e3a65f887b6225b368ad55b3fc27eccf3
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Dec 28 12:08:25 2017 +0000

    Extract common code into update_dmraid_entry() (#791875)
    
    Extract common code which updates a DMRaid device mapper entry into a
    sub-function.  This will also be needed when adding rollback of a
    partition change on failure.
    
    Bug 791875 - Rollback specific failed partition change steps

 include/GParted_Core.h |    1 +
 src/GParted_Core.cc    |   50 +++++++++++++++++++++--------------------------
 2 files changed, 23 insertions(+), 28 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index a4f9089..b805e95 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -205,6 +205,7 @@ private:
        bool calculate_exact_geom( const Partition & partition_old,
                                   Partition & partition_new,
                                   OperationDetail & operationdetail ) ;
+       bool update_dmraid_entry( const Partition & partition_new, OperationDetail & operationdetail );
        bool erase_filesystem_signatures( const Partition & partition, OperationDetail & operationdetail ) ;
        bool update_bootsector( const Partition & partition, OperationDetail & operationdetail ) ;
 
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index e3e9243..6a84201 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2753,21 +2753,8 @@ bool GParted_Core::resize_move_partition( const Partition & partition_old,
                        STATUS_NONE, 
                        FONT_ITALIC ) ) ;
 
-#ifndef USE_LIBPARTED_DMRAID
                //update dev mapper entry if partition is dmraid.
-               DMRaid dmraid ;
-               if ( success && dmraid.is_dmraid_device( partition_new.device_path ) )
-               {
-                       PedDevice* lp_device = NULL ;
-                       PedDisk* lp_disk = NULL ;
-                       //Open disk handle before and close after to prevent application crash.
-                       if ( get_device_and_disk( partition_new .device_path, lp_device, lp_disk ) )
-                       {
-                               success = dmraid.update_dev_map_entry( partition_new, 
operationdetail.get_last_child() );
-                               destroy_device_and_disk( lp_device, lp_disk ) ;
-                       }
-               }
-#endif
+               success = success && update_dmraid_entry( partition_new, operationdetail );
        }
        else
        {
@@ -3708,27 +3695,34 @@ bool GParted_Core::calculate_exact_geom( const Partition & partition_old,
                        STATUS_NONE,
                        FONT_ITALIC ) ) ;
 
-#ifndef USE_LIBPARTED_DMRAID
                //Update dev mapper entry if partition is dmraid.
-               DMRaid dmraid ;
-               if ( succes && dmraid .is_dmraid_device( partition_new .device_path ) )
-               {
-                       PedDevice* lp_device = NULL ;
-                       PedDisk* lp_disk = NULL ;
-                       //Open disk handle before and close after to prevent application crash.
-                       if ( get_device_and_disk( partition_new .device_path, lp_device, lp_disk ) )
-                       {
-                               succes = dmraid .update_dev_map_entry( partition_new, operationdetail 
.get_last_child() ) ;
-                               destroy_device_and_disk( lp_device, lp_disk ) ;
-                       }
-               }
-#endif
+               succes = succes && update_dmraid_entry( partition_new, operationdetail );
        }
 
        operationdetail.get_last_child().set_success_and_capture_errors( succes );
        return succes ;
 }
 
+bool GParted_Core::update_dmraid_entry( const Partition & partition, OperationDetail & operationdetail )
+{
+       bool success = true;
+#ifndef USE_LIBPARTED_DMRAID
+       DMRaid dmraid;
+       if ( dmraid.is_dmraid_device( partition.device_path ) )
+       {
+               PedDevice *lp_device = NULL;
+               PedDisk *lp_disk;
+               // Open disk handle before and close after to prevent application crash.
+               if ( get_device_and_disk( partition.device_path, lp_device, lp_disk ) )
+               {
+                       success = dmraid.update_dev_map_entry( partition, operationdetail.get_last_child() );
+                       destroy_device_and_disk( lp_device, lp_disk );
+               }
+       }
+#endif
+       return success;
+}
+
 FileSystem * GParted_Core::get_filesystem_object( FILESYSTEM filesystem )
 {
        if ( FILESYSTEM_MAP .count( filesystem ) )


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