[gparted] Simplify Partition object to a single path (#767842)



commit 214255eda3160bdee2eab985451f9231b75cd783
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Jun 2 21:48:06 2016 +0100

    Simplify Partition object to a single path (#767842)
    
    Change from a vector of paths to a single path member in the Partition
    object.  Remove add_paths() and get_paths() methods.  Keep add_path()
    and get_path().
    
    Bug 767842 - File system usage missing when tools report alternate block
                 device names

 include/Partition.h          |    7 +----
 src/Dialog_Partition_Info.cc |    8 ++--
 src/GParted_Core.cc          |   38 ++++++++----------------
 src/Partition.cc             |   63 ++++++------------------------------------
 4 files changed, 27 insertions(+), 89 deletions(-)
---
diff --git a/include/Partition.h b/include/Partition.h
index cf05b04..2a7cbde 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -102,11 +102,9 @@ public:
        void Update_Number( int new_number );
        
        void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
-       void add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths = false ) ;
        Byte_Value get_byte_length() const ;
        Sector get_sector_length() const ; 
        Glib::ustring get_path() const ;
-       std::vector<Glib::ustring> get_paths() const ;
        void add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints = false ) ;
        void add_mountpoints( const std::vector<Glib::ustring> & mountpoints, bool clear_mountpoints = false 
) ;
        Glib::ustring get_mountpoint() const ; 
@@ -169,12 +167,9 @@ private:
 
        static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & 
i1, int & i2, int & i3 ) ;
 
-       void sort_paths_and_remove_duplicates() ;
        Sector calc_significant_unallocated_sectors() const ;
 
-       static bool compare_paths( const Glib::ustring & A, const Glib::ustring & B ) ;
-       
-       std::vector<Glib::ustring> paths ;
+       Glib::ustring path;
        std::vector<Glib::ustring> mountpoints ;
        bool have_filesystem_label;
        Glib::ustring filesystem_label;
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index 6d84b27..0bfcb6c 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -595,10 +595,10 @@ void Dialog_Partition_Info::Display_Info()
                        1, 2,
                        top, bottom,
                        Gtk::FILL ) ;
-       table ->attach( * Utils::mk_label( Glib::build_path( "\n", partition .get_paths() ), true, false, 
true ),
-                       2, 3,
-                       top++, bottom++,
-                       Gtk::FILL ) ;
+       table->attach( * Utils::mk_label( partition.get_path(), true, false, true ),
+                      2, 3,
+                      top++, bottom++,
+                      Gtk::FILL );
 
        if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW )
        {
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index a68a3cc..5afec2c 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -757,12 +757,12 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
                        if ( ! success )
                                break;
 
-                       // Replace the new partition object's list of paths from the
-                       // calibration in case the first path is "Copy of ..." from the
-                       // partition having been newly created by a paste into unallocated
-                       // space earlier in the sequence of operations now being applied.
-                       operation->get_partition_new().add_paths( 
operation->get_partition_original().get_paths(),
-                                                                 true );
+                       // Replace the new partition object's path from the calibration in
+                       // case the path is "Copy of ..." from the partition having been
+                       // newly created by a paste into unallocated space earlier in the
+                       // sequence of operations now being applied.
+                       operation->get_partition_new().add_path( 
operation->get_partition_original().get_path(),
+                                                                true );
 
                        success = resize_move( operation->get_partition_original(),
                                               operation->get_partition_new(),
@@ -774,12 +774,12 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
                        if ( ! success )
                                break;
 
-                       // Replace the original partition object's list of paths from the
-                       // calibration in case the first path is "Copy of ..." from the
+                       // Replace the original partition object's path from the
+                       // calibration in case the path is "Copy of ..." from the
                        // partition having been newly created by a paste into unallocated
                        // space earlier in the sequence of operations now being applied.
-                       operation->get_partition_original().add_paths( 
operation->get_partition_new().get_paths(),
-                                                                      true );
+                       operation->get_partition_original().add_path( 
operation->get_partition_new().get_path(),
+                                                                     true );
 
                        success =    remove_filesystem( operation->get_partition_original(),
                                                        operation->operation_detail )
@@ -1235,7 +1235,6 @@ void GParted_Core::set_device_serial_number( Device & device )
 void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk )
 {
        int EXT_INDEX = -1 ;
-       Proc_Partitions_Info pp_info ; //Use cache of proc partitions information
 #ifndef USE_LIBPARTED_DMRAID
        DMRaid dmraid ;    //Use cache of dmraid device information
 #endif
@@ -1310,7 +1309,7 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
                                                     ( lp_partition->type == PED_PARTITION_LOGICAL ),
                                                     partition_is_busy );
                                partition_temp->append_messages( detect_messages );
-                               partition_temp->add_paths( pp_info.get_alternate_paths( 
partition_temp->get_path() ) );
+
                                set_flags( *partition_temp, lp_partition );
 
                                if ( filesystem == FS_LUKS )
@@ -1334,7 +1333,6 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
                                                     false,
                                                     false );
 
-                               partition_temp->add_paths( pp_info.get_alternate_paths( 
partition_temp->get_path() ) );
                                set_flags( *partition_temp, lp_partition );
 
                                EXT_INDEX = device .partitions .size() ;
@@ -1399,8 +1397,6 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
 void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
                                              std::vector<Glib::ustring> & messages )
 {
-       Proc_Partitions_Info pp_info;  // Use cache of proc partitions information
-
        device.partitions.clear();
 
        Glib::ustring path = lp_device->path;
@@ -1424,7 +1420,6 @@ void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_dev
                             partition_is_busy );
 
        partition_temp->append_messages( messages );
-       partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
 
        if ( fstype == FS_LUKS )
                set_luks_partition( *dynamic_cast<PartitionLUKS *>( partition_temp ) );
@@ -1476,9 +1471,6 @@ void GParted_Core::set_luks_partition( PartitionLUKS & partition )
                       fs_busy );
        encrypted.append_messages( detect_messages );
 
-       Proc_Partitions_Info pp_info;  // Use cache of proc partitions information
-       encrypted.add_paths( pp_info.get_alternate_paths( encrypted.get_path() ) );
-
        set_partition_label_and_uuid( encrypted );
        set_mountpoints( encrypted );
        set_used_sectors( encrypted, NULL );
@@ -1871,12 +1863,8 @@ void GParted_Core::set_mountpoints( Partition & partition )
 #endif
                        {
                                // Normal device, not DMRaid device
-                               for ( unsigned int i = 0 ; i < partition.get_paths() .size() ; i++ )
-                               {
-                                       Glib::ustring path = partition.get_paths()[i];
-                                       if ( set_mountpoints_helper( partition, path ) )
-                                               return;
-                               }
+                               if ( set_mountpoints_helper( partition, partition.get_path() ) )
+                                       return;
                        }
 
                        if ( partition.get_mountpoints().empty() )
diff --git a/src/Partition.cc b/src/Partition.cc
index 7c41e6d..6481aac 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -36,7 +36,7 @@ Partition * Partition::clone() const
 
 void Partition::Reset()
 {
-       paths .clear() ;
+       path.clear();
        messages .clear() ;
        status = GParted::STAT_REAL ;
        type = GParted::TYPE_UNALLOCATED ;
@@ -71,9 +71,7 @@ void Partition::Set( const Glib::ustring & device_path,
                      bool busy )
 {
        this ->device_path = device_path ;
-
-       paths .push_back( partition ) ;
-
+       this->path = partition;
        this ->partition_number = partition_number;
        this ->type = type;
        this->whole_device = whole_device;
@@ -191,40 +189,20 @@ void Partition::Set_Unallocated( const Glib::ustring & device_path,
 
 void Partition::Update_Number( int new_number )
 {  
-       unsigned int index ;
-       for ( unsigned int t = 0 ; t < paths .size() ; t++ )
-       {
-               index = paths[ t ] .rfind( Utils::num_to_str( partition_number ) ) ;
-
-               if ( index < paths[ t ] .length() )
-                       paths[ t ] .replace( index,
-                                      Utils::num_to_str( partition_number ) .length(),
-                                      Utils::num_to_str( new_number ) ) ;
-       }
+       unsigned int index = path.rfind( Utils::num_to_str( partition_number ) );
+       if ( index < path.length() )
+               path.replace( index,
+                             Utils::num_to_str( partition_number ).length(),
+                             Utils::num_to_str( new_number ) );
 
        partition_number = new_number;
 }
        
 void Partition::add_path( const Glib::ustring & path, bool clear_paths ) 
 {
-       if ( clear_paths )
-               paths .clear() ;
-
-       paths .push_back( path ) ;
-
-       sort_paths_and_remove_duplicates() ;
+       this->path = path;
 }
        
-void Partition::add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths )
-{
-       if ( clear_paths )
-               this ->paths .clear() ;
-
-       this ->paths .insert( this ->paths .end(), paths .begin(), paths .end() ) ;
-
-       sort_paths_and_remove_duplicates() ;
-}
-
 Byte_Value Partition::get_byte_length() const 
 {
        if ( get_sector_length() >= 0 )
@@ -243,15 +221,7 @@ Sector Partition::get_sector_length() const
 
 Glib::ustring Partition::get_path() const
 {
-       if ( paths .size() > 0 )
-               return paths .front() ;
-       
-       return "" ;
-}
-
-std::vector<Glib::ustring> Partition::get_paths() const
-{
-       return paths ;
+       return path;
 }
 
 bool Partition::filesystem_label_known() const
@@ -338,16 +308,6 @@ void Partition::get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sect
        }
 }
 
-void Partition::sort_paths_and_remove_duplicates()
-{
-       //remove duplicates
-       std::sort( paths .begin(), paths .end() ) ;
-       paths .erase( std::unique( paths .begin(), paths .end() ), paths .end() ) ;
-
-       //sort on length
-       std::sort( paths .begin(), paths .end(), compare_paths ) ;
-}
-
 void Partition::add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints )
 {
        if ( clear_mountpoints )
@@ -396,11 +356,6 @@ void Partition::clear_mountpoints()
        mountpoints .clear() ;
 }
 
-bool Partition::compare_paths( const Glib::ustring & A, const Glib::ustring & B )
-{
-       return A .length() < B .length() ;
-}
-
 //Return threshold of sectors which is considered above the intrinsic
 //  level for a file system which "fills" the partition.  Calculation
 //  is:


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