[gparted] Extract common code into new method get_lp_partition()
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Extract common code into new method get_lp_partition()
- Date: Tue, 3 Oct 2017 16:36:33 +0000 (UTC)
commit 33a535390e00cf7de42ba2046e1a7093f426159f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Sep 26 08:06:29 2017 +0100
Extract common code into new method get_lp_partition()
include/GParted_Core.h | 1 +
src/GParted_Core.cc | 51 ++++++++++++++---------------------------------
2 files changed, 16 insertions(+), 36 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index e675202..26771f0 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -218,6 +218,7 @@ private:
static bool commit_to_os( PedDisk* lp_disk, std::time_t timeout );
static void settle_device( std::time_t timeout );
static bool useable_device( PedDevice * lp_device );
+ static PedPartition* get_lp_partition( const PedDisk* lp_disk, const Partition & partition );
static PedExceptionOption ped_exception_handler( PedException * e ) ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 663032f..8223db6 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -51,6 +51,7 @@
#include "udf.h"
#include "ufs.h"
+#include <parted/parted.h>
#include <cerrno>
#include <cstring>
#include <sys/types.h>
@@ -761,12 +762,7 @@ bool GParted_Core::toggle_flag( const Partition & partition, const Glib::ustring
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition .device_path, lp_device, lp_disk ) )
{
- PedPartition* lp_partition = NULL ;
- if ( partition .type == GParted::TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk ) ;
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
-
+ PedPartition* lp_partition = get_lp_partition( lp_disk, partition );
if ( lp_partition )
{
PedPartitionFlag lp_flag = ped_partition_flag_get_by_name( flag .c_str() ) ;
@@ -822,12 +818,7 @@ std::map<Glib::ustring, bool> GParted_Core::get_available_flags( const Partition
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition .device_path, lp_device, lp_disk ) )
{
- PedPartition* lp_partition = NULL ;
- if ( partition .type == GParted::TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk ) ;
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
-
+ PedPartition* lp_partition = get_lp_partition( lp_disk, partition );
if ( lp_partition )
{
for ( unsigned int t = 0 ; t < flags .size() ; t++ )
@@ -2083,12 +2074,8 @@ bool GParted_Core::delete_partition( const Partition & partition, OperationDetai
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition .device_path, lp_device, lp_disk ) )
{
- PedPartition* lp_partition = NULL ;
- if ( partition .type == TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk ) ;
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
-
+ PedPartition* lp_partition = get_lp_partition( lp_disk, partition );
+
succes = ped_disk_delete_partition( lp_disk, lp_partition ) && commit( lp_disk ) ;
destroy_device_and_disk( lp_device, lp_disk ) ;
@@ -2773,12 +2760,7 @@ bool GParted_Core::resize_move_partition( const Partition & partition_old,
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition_old .device_path, lp_device, lp_disk ) )
{
- PedPartition* lp_partition = NULL ;
- if ( partition_old .type == GParted::TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk ) ;
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition_old .get_sector()
) ;
-
+ PedPartition* lp_partition = get_lp_partition( lp_disk, partition_old );
if ( lp_partition )
{
if ( (partition_new .alignment == ALIGN_STRICT)
@@ -3567,12 +3549,7 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
else if ( get_disk( lp_device, lp_disk ) )
{
// Partitioned device
- PedPartition *lp_partition = NULL;
- if ( partition.type == TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk );
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk,
partition.get_sector() );
-
+ PedPartition *lp_partition = get_lp_partition( lp_disk, partition );
if ( lp_partition ) // FIXME: add check to see if lp_partition->type matches
partition.type..
{
if ( ! file_test( curr_path, Glib::FILE_TEST_EXISTS ) )
@@ -3679,12 +3656,7 @@ bool GParted_Core::calculate_exact_geom( const Partition & partition_old,
PedDisk* lp_disk = NULL ;
if ( get_device_and_disk( partition_old .device_path, lp_device, lp_disk ) )
{
- PedPartition* lp_partition = NULL ;
- if ( partition_old .type == GParted::TYPE_EXTENDED )
- lp_partition = ped_disk_extended_partition( lp_disk ) ;
- else
- lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition_old .get_sector()
) ;
-
+ PedPartition* lp_partition = get_lp_partition( lp_disk, partition_old );
if ( lp_partition )
{
PedConstraint *constraint = NULL ;
@@ -4307,6 +4279,13 @@ void GParted_Core::settle_device( std::time_t timeout )
sleep( timeout ) ;
}
+PedPartition* GParted_Core::get_lp_partition( const PedDisk* lp_disk, const Partition & partition )
+{
+ if ( partition.type == TYPE_EXTENDED )
+ return ped_disk_extended_partition( lp_disk );
+ return ped_disk_get_partition_by_sector( lp_disk, partition.get_sector() );
+}
+
class PedExceptionMsg : public Gtk::MessageDialog
{
public:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]