[gparted] Use Partition pointer adoption everywhere when adding items into a PartitionVector (#759726)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Use Partition pointer adoption everywhere when adding items into a PartitionVector (#759726)
- Date: Sat, 30 Jan 2016 17:39:54 +0000 (UTC)
commit f6b45a0429bf4e52024651625aeb9433f190e8ee
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Fri Dec 4 13:14:41 2015 +0000
Use Partition pointer adoption everywhere when adding items into a PartitionVector (#759726)
Replace all the current code which uses push_back() and insert() of a
local Partition object and gets it copy constructed into a
PartitionVector. Instead allocate a Partition object on the heap and
adopt a pointer into the PartitionVector using push_back_adopt() and
insert_adopt().
Bug 759726 - Implement Partition object polymorphism
src/Dialog_Partition_New.cc | 16 ++--
src/Dialog_Rescue_Data.cc | 9 +-
src/GParted_Core.cc | 224 +++++++++++++++++++++----------------------
src/OperationFormat.cc | 16 ++--
4 files changed, 130 insertions(+), 135 deletions(-)
---
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index de78fc1..b3a9ad4 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -278,14 +278,14 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
// partition boundaries.
if ( new_partition.type == TYPE_EXTENDED )
{
- Partition unallocated;
- unallocated.Set_Unallocated( new_partition.device_path,
- new_partition.whole_device,
- new_partition.sector_start,
- new_partition.sector_end,
- sector_size,
- true );
- new_partition.logicals.push_back( unallocated );
+ Partition * unallocated = new Partition();
+ unallocated->Set_Unallocated( new_partition.device_path,
+ new_partition.whole_device,
+ new_partition.sector_start,
+ new_partition.sector_end,
+ sector_size,
+ true );
+ new_partition.logicals.push_back_adopt( unallocated );
}
return new_partition;
diff --git a/src/Dialog_Rescue_Data.cc b/src/Dialog_Rescue_Data.cc
index a54a02a..a8ab6fc 100644
--- a/src/Dialog_Rescue_Data.cc
+++ b/src/Dialog_Rescue_Data.cc
@@ -330,7 +330,6 @@ void Dialog_Rescue_Data::read_partitions_from_buffer()
if(line.find("Primary partition")!=line.npos)
{
// Parameters of Partition::Set
- Partition part;
Glib::ustring dev_path=this->device_path;
Glib::ustring part_path;
int part_num;
@@ -429,10 +428,10 @@ void Dialog_Rescue_Data::read_partitions_from_buffer()
continue;
}
- part.Set(dev_path, part_path, part_num,
- type, false, fs, sec_start, sec_end, sec_size, false, false);
-
- this->partitions.push_back(part);
+ Partition * part = new Partition();
+ part->Set( dev_path, part_path, part_num,
+ type, false, fs, sec_start, sec_end, sec_size, false, false );
+ this->partitions.push_back_adopt( part );
}
}
}
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index f93d6db..b5dc7b5 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -342,21 +342,21 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
// Create virtual partition covering the whole disk device
// with unknown contents.
- Partition partition_temp;
- partition_temp.Set( temp_device.get_path(),
- lp_device->path,
- 1,
- TYPE_PRIMARY,
- true,
- FS_UNKNOWN,
- 0LL,
- temp_device.length - 1LL,
- temp_device.sector_size,
- false,
- false );
+ Partition * partition_temp = new Partition();
+ partition_temp->Set( temp_device.get_path(),
+ lp_device->path,
+ 1,
+ TYPE_PRIMARY,
+ true,
+ FS_UNKNOWN,
+ 0LL,
+ temp_device.length - 1LL,
+ temp_device.sector_size,
+ false,
+ false );
// Place unknown file system message in this partition.
- partition_temp.messages = messages;
- temp_device.partitions.push_back( partition_temp );
+ partition_temp->messages = messages;
+ temp_device.partitions.push_back_adopt( partition_temp );
}
// Unrecognised, unpartitioned drive.
else
@@ -369,19 +369,19 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
_("unrecognized") ;
temp_device.max_prims = 1;
- Partition partition_temp;
- partition_temp.Set_Unallocated( temp_device .get_path(),
- true,
- 0LL,
- temp_device .length - 1LL,
- temp_device .sector_size,
- false );
+ Partition * partition_temp = new Partition();
+ partition_temp->Set_Unallocated( temp_device.get_path(),
+ true,
+ 0LL,
+ temp_device.length - 1LL,
+ temp_device.sector_size,
+ false );
// Place libparted messages in this unallocated partition
- partition_temp.messages.insert( partition_temp.messages.end(),
- libparted_messages.begin(),
- libparted_messages.end() );
+ partition_temp->messages.insert( partition_temp->messages.end(),
+ libparted_messages.begin(),
+ libparted_messages.end() );
libparted_messages.clear();
- temp_device.partitions.push_back( partition_temp );
+ temp_device.partitions.push_back_adopt( partition_temp );
}
devices .push_back( temp_device ) ;
@@ -1237,9 +1237,10 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
while ( lp_partition )
{
libparted_messages .clear() ;
- Partition partition_temp ;
+ Partition * partition_temp = NULL;
bool partition_is_busy = false ;
- GParted::FILESYSTEM filesystem ;
+ GParted::FILESYSTEM filesystem;
+ std::vector<Glib::ustring> detect_messages;
//Retrieve partition path
Glib::ustring partition_path = get_partition_path( lp_partition );
@@ -1248,7 +1249,7 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
{
case PED_PARTITION_NORMAL:
case PED_PARTITION_LOGICAL:
- filesystem = detect_filesystem( lp_device, lp_partition,
partition_temp.messages );
+ filesystem = detect_filesystem( lp_device, lp_partition, detect_messages );
#ifndef USE_LIBPARTED_DMRAID
//Handle dmraid devices differently because the minor number might not
// match the last number of the partition filename as shown by "ls -l
/dev/mapper"
@@ -1268,41 +1269,42 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
partition_is_busy = is_busy( filesystem, partition_path ) ;
}
- partition_temp.Set( device .get_path(),
- partition_path,
- lp_partition->num,
- ( lp_partition->type == 0 ) ? TYPE_PRIMARY : TYPE_LOGICAL,
- false,
- filesystem,
- lp_partition->geom.start,
- lp_partition->geom.end,
- device.sector_size,
- lp_partition->type,
- partition_is_busy );
-
- partition_temp .add_paths( pp_info .get_alternate_paths( partition_temp
.get_path() ) ) ;
- set_flags( partition_temp, lp_partition ) ;
-
- if ( partition_temp .busy && partition_temp .partition_number > device
.highest_busy )
- device .highest_busy = partition_temp .partition_number ;
-
+ partition_temp = new Partition();
+ partition_temp->Set( device .get_path(),
+ partition_path,
+ lp_partition->num,
+ ( lp_partition->type == 0 ) ? TYPE_PRIMARY :
TYPE_LOGICAL,
+ false,
+ filesystem,
+ lp_partition->geom.start,
+ lp_partition->geom.end,
+ device.sector_size,
+ lp_partition->type,
+ partition_is_busy );
+ partition_temp->messages = detect_messages;
+ partition_temp->add_paths( pp_info.get_alternate_paths(
partition_temp->get_path() ) );
+ set_flags( *partition_temp, lp_partition );
+
+ if ( partition_temp->busy && partition_temp->partition_number >
device.highest_busy )
+ device.highest_busy = partition_temp->partition_number;
break ;
case PED_PARTITION_EXTENDED:
- partition_temp.Set( device.get_path(),
- partition_path,
- lp_partition->num,
- TYPE_EXTENDED,
- false,
- FS_EXTENDED,
- lp_partition->geom.start,
- lp_partition->geom.end,
- device.sector_size,
- false,
- false );
-
- partition_temp .add_paths( pp_info .get_alternate_paths( partition_temp
.get_path() ) ) ;
- set_flags( partition_temp, lp_partition ) ;
+ partition_temp = new Partition();
+ partition_temp->Set( device.get_path(),
+ partition_path,
+ lp_partition->num,
+ TYPE_EXTENDED,
+ false,
+ FS_EXTENDED,
+ lp_partition->geom.start,
+ lp_partition->geom.end,
+ device.sector_size,
+ 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() ;
break ;
@@ -1311,27 +1313,24 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
break;
}
- //Avoid reading additional file system information if there is no path
- if ( partition_temp .get_path() != "" )
+ // Only for libparted reported partition types that we care about: NORMAL,
+ // LOGICAL, EXTENDED
+ if ( partition_temp != NULL )
{
- set_partition_label_and_uuid( partition_temp );
+ set_partition_label_and_uuid( *partition_temp );
// Retrieve partition name
if ( device.partition_naming_supported() )
- partition_temp.name = Glib::ustring( ped_partition_get_name( lp_partition ) );
- }
+ partition_temp->name = Glib::ustring( ped_partition_get_name( lp_partition )
);
- partition_temp .messages .insert( partition_temp .messages .end(),
- libparted_messages. begin(),
- libparted_messages .end() ) ;
-
- //if there's an end, there's a partition ;)
- if ( partition_temp .sector_end > -1 )
- {
- if ( ! partition_temp .inside_extended )
- device .partitions .push_back( partition_temp );
+ partition_temp->messages.insert( partition_temp->messages.end(),
+ libparted_messages.begin(),
+ libparted_messages.end() );
+
+ if ( ! partition_temp->inside_extended )
+ device.partitions.push_back_adopt( partition_temp );
else
- device .partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ;
+ device.partitions[EXT_INDEX].logicals.push_back_adopt( partition_temp );
}
//next partition (if any)
@@ -1374,28 +1373,28 @@ void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_dev
Glib::ustring path = lp_device->path;
bool partition_is_busy = is_busy( fstype, path );
- Partition partition_temp;
- partition_temp.Set( device.get_path(),
- path,
- 1,
- TYPE_PRIMARY,
- true,
- fstype,
- 0LL,
- device.length - 1LL,
- device.sector_size,
- false,
- partition_is_busy );
-
- partition_temp.messages = messages;
- partition_temp.add_paths( pp_info.get_alternate_paths( partition_temp.get_path() ) );
-
- if ( partition_temp.busy )
+ Partition * partition_temp = new Partition();
+ partition_temp->Set( device.get_path(),
+ path,
+ 1,
+ TYPE_PRIMARY,
+ true,
+ fstype,
+ 0LL,
+ device.length - 1LL,
+ device.sector_size,
+ false,
+ partition_is_busy );
+
+ partition_temp->messages = messages;
+ partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
+
+ if ( partition_temp->busy )
device.highest_busy = 1;
- set_partition_label_and_uuid( partition_temp );
+ set_partition_label_and_uuid( *partition_temp );
- device.partitions.push_back( partition_temp );
+ device.partitions.push_back_adopt( partition_temp );
}
void GParted_Core::set_partition_label_and_uuid( Partition & partition )
@@ -1685,27 +1684,22 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
Byte_Value sector_size,
bool inside_extended )
{
- Partition partition_temp ;
- partition_temp.Set_Unallocated( device_path, false, 0LL, 0LL, sector_size, inside_extended );
-
//if there are no partitions at all..
if ( partitions .empty() )
{
- partition_temp .sector_start = start ;
- partition_temp .sector_end = end ;
-
- partitions .push_back( partition_temp );
-
+ Partition * partition_temp = new Partition();
+ partition_temp->Set_Unallocated( device_path, false, start, end, sector_size, inside_extended
);
+ partitions.push_back_adopt( partition_temp );
return ;
}
//start <---> first partition start
if ( (partitions .front() .sector_start - start) > (MEBIBYTE / sector_size) )
{
- partition_temp .sector_start = start ;
- partition_temp .sector_end = partitions .front() .sector_start -1 ;
-
- partitions .insert( partitions .begin(), partition_temp );
+ Sector temp_end = partitions.front().sector_start - 1;
+ Partition * partition_temp = new Partition();
+ partition_temp->Set_Unallocated( device_path, false, start, temp_end, sector_size,
inside_extended );
+ partitions.insert_adopt( partitions.begin(), partition_temp );
}
//look for gaps in between
@@ -1717,20 +1711,22 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
)
)
{
- partition_temp .sector_start = partitions[ t ] .sector_end +1 ;
- partition_temp .sector_end = partitions[ t +1 ] .sector_start -1 ;
-
- partitions .insert( partitions .begin() + ++t, partition_temp );
+ Sector temp_start = partitions[t].sector_end + 1;
+ Sector temp_end = partitions[t+1].sector_start - 1;
+ Partition * partition_temp = new Partition();
+ partition_temp->Set_Unallocated( device_path, false, temp_start, temp_end,
+ sector_size, inside_extended );
+ partitions.insert_adopt( partitions.begin() + ++t, partition_temp );
}
}
//last partition end <---> end
if ( (end - partitions .back() .sector_end) >= (MEBIBYTE / sector_size) )
{
- partition_temp .sector_start = partitions .back() .sector_end +1 ;
- partition_temp .sector_end = end ;
-
- partitions .push_back( partition_temp );
+ Sector temp_start = partitions.back().sector_end + 1;
+ Partition * partition_temp = new Partition();
+ partition_temp->Set_Unallocated( device_path, false, temp_start, end, sector_size,
inside_extended );
+ partitions.push_back_adopt( partition_temp );
}
}
diff --git a/src/OperationFormat.cc b/src/OperationFormat.cc
index 853b87d..c774f28 100644
--- a/src/OperationFormat.cc
+++ b/src/OperationFormat.cc
@@ -40,14 +40,14 @@ void OperationFormat::apply_to_visual( PartitionVector & partitions )
// unallocated device, matching what happens when implemented.
partitions.clear();
- Partition temp_partition;
- temp_partition.Set_Unallocated( device.get_path(),
- true,
- 0LL,
- device.length -1LL,
- device.sector_size,
- false );
- partitions.push_back( temp_partition );
+ Partition * temp_partition = new Partition();
+ temp_partition->Set_Unallocated( device.get_path(),
+ true,
+ 0LL,
+ device.length -1LL,
+ device.sector_size,
+ false );
+ partitions.push_back_adopt( temp_partition );
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]