[gparted] Change methods to use Partition pointers locally (#759726)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Change methods to use Partition pointers locally (#759726)
- Date: Sat, 30 Jan 2016 17:40:19 +0000 (UTC)
commit 4d8578646c7deed70cbc1c7192128af172c9c4c3
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun Dec 13 13:20:21 2015 +0000
Change methods to use Partition pointers locally (#759726)
A number of methods in GParted_Core and Win_GParted were using local
Partition objects. Change them into pointers so that Partition object
polymorphism can be implemented.
Bug 759726 - Implement Partition object polymorphism
src/GParted_Core.cc | 72 +++++++++++++++++++++++++++-----------------
src/Win_GParted.cc | 81 +++++++++++++++++++++++++++++++--------------------
2 files changed, 93 insertions(+), 60 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index c3b43e6..e76951b 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2399,29 +2399,34 @@ bool GParted_Core::resize_move( const Partition & partition_old,
return resize( partition_old, partition_new, operationdetail ) ;
if ( partition_new .get_sector_length() == partition_old .get_sector_length() )
+ {
return move( partition_old, partition_new, operationdetail );
-
- Partition temp ;
+ }
+ Partition * temp = NULL;
if ( partition_new .get_sector_length() > partition_old .get_sector_length() )
{
//first move, then grow. Since old.length < new.length and new.start is valid, temp
is valid.
- temp = partition_new ;
- temp .sector_end = temp .sector_start + partition_old .get_sector_length() -1 ;
+ temp = new Partition( partition_new );
+ temp->sector_end = temp->sector_start + partition_old.get_sector_length() - 1;
}
-
- if ( partition_new .get_sector_length() < partition_old .get_sector_length() )
+ else // ( partition_new.get_sector_length() < partition_old.get_sector_length() )
{
//first shrink, then move. Since new.length < old.length and old.start is valid, temp
is valid.
- temp = partition_old ;
- temp .sector_end = partition_old .sector_start + partition_new .get_sector_length()
-1 ;
+ temp = new Partition( partition_old );
+ temp->sector_end = partition_old.sector_start + partition_new.get_sector_length() - 1;
}
- PartitionAlignment previous_alignment = temp .alignment ;
- temp .alignment = ALIGN_STRICT ;
- bool succes = resize_move( partition_old, temp, operationdetail );
- temp .alignment = previous_alignment ;
+ PartitionAlignment previous_alignment = temp->alignment;
+ temp->alignment = ALIGN_STRICT;
+ bool success = resize_move( partition_old, *temp, operationdetail );
+ temp->alignment = previous_alignment;
+ if ( success )
+ success = resize_move( *temp, partition_new, operationdetail );
+
+ delete temp;
+ temp = NULL;
- return succes && resize_move( temp, partition_new, operationdetail );
+ return success;
}
return false ;
@@ -3191,32 +3196,43 @@ void GParted_Core::rollback_transaction( const Partition & partition_src,
if ( total_done > 0 )
{
//find out exactly which part of the file system was copied (and to where it was copied)..
- Partition temp_src = partition_src ;
- Partition temp_dst = partition_dst ;
+ Partition * temp_src = new Partition( partition_src );
+ Partition * temp_dst = new Partition( partition_dst );
+ bool rollback_needed = true;
if ( partition_dst .sector_start > partition_src .sector_start )
{
Sector distance = partition_dst.sector_start - partition_src.sector_start;
- temp_src.sector_start = temp_src.sector_end - ( (total_done / temp_src.sector_size) -
1 ) + distance;
- temp_dst.sector_start = temp_dst.sector_end - ( (total_done / temp_dst.sector_size) -
1 ) + distance;
- if (temp_src.sector_start > temp_src.sector_end)
- return; /* nothing has been overwritten yet, so nothing to roll back */
-
+ temp_src->sector_start = temp_src->sector_end - ( (total_done /
temp_src->sector_size) - 1 ) + distance;
+ temp_dst->sector_start = temp_dst->sector_end - ( (total_done /
temp_dst->sector_size) - 1 ) + distance;
+ if ( temp_src->sector_start > temp_src->sector_end )
+ // Nothing has been overwritten yet, so nothing to roll back
+ rollback_needed = false;
}
else
{
Sector distance = partition_src.sector_start - partition_dst.sector_start;
- temp_src.sector_end = temp_src.sector_start + ( (total_done / temp_src.sector_size) -
1 ) - distance;
- temp_dst.sector_end = temp_dst.sector_start + ( (total_done / temp_dst.sector_size) -
1 ) - distance;
- if (temp_src.sector_start > temp_src.sector_end)
- return; /* nothing has been overwritten yet, so nothing to roll back */
+ temp_src->sector_end = temp_src->sector_start + ( (total_done /
temp_src->sector_size) - 1 ) - distance;
+ temp_dst->sector_end = temp_dst->sector_start + ( (total_done /
temp_dst->sector_size) - 1 ) - distance;
+ if ( temp_src->sector_start > temp_src->sector_end )
+ // Nothing has been overwritten yet, so nothing to roll back
+ rollback_needed = false;
}
- operationdetail.add_child( OperationDetail( _("roll back last transaction") ) );
- //and copy it back (NOTE the reversed dst and src)
- bool succes = copy_filesystem( temp_dst, temp_src, operationdetail .get_last_child(), false )
;
+ if ( rollback_needed )
+ {
+ operationdetail.add_child( OperationDetail( _("roll back last transaction") ) );
- operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
+ //and copy it back (NOTE the reversed dst and src)
+ bool success = copy_filesystem( *temp_dst, *temp_src,
operationdetail.get_last_child(), false );
+
+ operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+ }
+
+ delete temp_src;
+ delete temp_dst;
+ temp_src = NULL;
+ temp_dst = NULL;
}
}
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index ac65f46..0870558 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1741,7 +1741,8 @@ void Win_GParted::activate_resize()
{
dialog .hide() ;
- Partition part_temp = dialog.Get_New_Partition( devices[current_device].sector_size );
+ Partition * part_temp = new Partition( dialog.Get_New_Partition(
devices[current_device].sector_size ) );
+
// When resizing/moving a partition which already exists on the disk all
// possible operations could be pending so only try merging with the
// previous operation.
@@ -1751,7 +1752,7 @@ void Win_GParted::activate_resize()
// it again with the new size and position ( unless it's an EXTENDED )
if ( selected_partition_ptr->status == STAT_NEW && selected_partition_ptr->type !=
TYPE_EXTENDED )
{
- part_temp.status = STAT_NEW;
+ part_temp->status = STAT_NEW;
// On a partition which is pending creation only resize/move and
// format operations are possible. These operations are always
// mergeable with the pending operation which will create the
@@ -1762,9 +1763,12 @@ void Win_GParted::activate_resize()
Operation * operation = new OperationResizeMove( devices[current_device],
*selected_partition_ptr,
- part_temp );
+ *part_temp );
operation->icon = render_icon( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU );
+ delete part_temp;
+ part_temp = NULL;
+
// Display warning if moving a non-extended partition which already exists
// on the disk.
if ( operation->get_partition_original().status != STAT_NEW
&&
@@ -1828,14 +1832,16 @@ void Win_GParted::activate_paste()
{
// We don't want the messages, mount points or name of the source
// partition for the new partition being created.
- Partition part_temp = *copied_partition;
- part_temp.messages.clear();
- part_temp.clear_mountpoints();
- part_temp.name.clear();
+ Partition * part_temp = new Partition( *copied_partition );
+ part_temp->messages.clear();
+ part_temp->clear_mountpoints();
+ part_temp->name.clear();
Dialog_Partition_Copy dialog( gparted_core.get_fs( copied_partition->filesystem ),
*selected_partition_ptr,
- part_temp );
+ *part_temp );
+ delete part_temp;
+ part_temp = NULL;
dialog .set_transient_for( *this );
if ( dialog .run() == Gtk::RESPONSE_OK )
@@ -1864,19 +1870,19 @@ void Win_GParted::activate_paste()
shown_dialog = true ;
}
- Partition partition_new = *selected_partition_ptr;
- partition_new .alignment = ALIGN_STRICT ;
- partition_new.filesystem = copied_partition->filesystem;
- partition_new.set_filesystem_label( copied_partition->get_filesystem_label() );
- partition_new.uuid = copied_partition->uuid;
- partition_new.color = copied_partition->color;
- Sector new_size = partition_new .get_sector_length() ;
+ Partition * partition_new = new Partition( *selected_partition_ptr );
+ partition_new->alignment = ALIGN_STRICT;
+ partition_new->filesystem = copied_partition->filesystem;
+ partition_new->set_filesystem_label( copied_partition->get_filesystem_label() );
+ partition_new->uuid = copied_partition->uuid;
+ partition_new->color = copied_partition->color;
+ Sector new_size = partition_new->get_sector_length();
if ( copied_partition->get_sector_length() == new_size )
{
// Pasting into same size existing partition, therefore only block
// copy operation will be performed maintaining the file system
// size.
- partition_new .set_sector_usage(
+ partition_new->set_sector_usage(
copied_partition->sectors_used + copied_partition->sectors_unused,
copied_partition->sectors_unused );
}
@@ -1885,18 +1891,21 @@ void Win_GParted::activate_paste()
// Pasting into larger existing partition, therefore block copy
// followed by file system grow operations (if supported) will be
// performed making the file system fill the partition.
- partition_new .set_sector_usage(
+ partition_new->set_sector_usage(
new_size,
new_size - copied_partition->sectors_used );
}
- partition_new .messages .clear() ;
+ partition_new->messages.clear();
Operation * operation = new OperationCopy( devices[current_device],
*selected_partition_ptr,
- partition_new,
+ *partition_new,
*copied_partition );
operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU );
+ delete partition_new;
+ partition_new = NULL;
+
Add_Operation( operation ) ;
if ( ! shown_dialog )
@@ -1913,7 +1922,7 @@ void Win_GParted::activate_paste()
/*TO TRANSLATORS: looks like The data in /dev/sda3 will be lost if you apply this
operation. */
dialog .set_secondary_text(
String::ucompose( _( "The data in %1 will be lost if you apply this
operation." ),
- partition_new .get_path() ) ) ;
+ selected_partition_ptr->get_path() ) );
dialog .run() ;
}
}
@@ -2646,14 +2655,17 @@ void Win_GParted::activate_label_filesystem()
{
dialog .hide() ;
// Make a duplicate of the selected partition (used in UNDO)
- Partition part_temp = *selected_partition_ptr;
+ Partition * part_temp = new Partition( *selected_partition_ptr );
- part_temp.set_filesystem_label( dialog.get_new_label() );
+ part_temp->set_filesystem_label( dialog.get_new_label() );
Operation * operation = new OperationLabelFileSystem( devices[current_device],
- *selected_partition_ptr, part_temp );
+ *selected_partition_ptr, *part_temp );
operation ->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
+ delete part_temp;
+ part_temp = NULL;
+
Add_Operation( operation ) ;
// Try to merge this label file system operation with all previous
// operations.
@@ -2677,14 +2689,17 @@ void Win_GParted::activate_name_partition()
{
dialog.hide();
// Make a duplicate of the selected partition (used in UNDO)
- Partition part_temp = *selected_partition_ptr;
+ Partition * part_temp = new Partition( *selected_partition_ptr );
- part_temp.name = dialog.get_new_name();
+ part_temp->name = dialog.get_new_name();
Operation * operation = new OperationNamePartition( devices[current_device],
- *selected_partition_ptr, part_temp );
+ *selected_partition_ptr, *part_temp );
operation->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
+ delete part_temp;
+ part_temp = NULL;
+
Add_Operation( operation );
// Try to merge this name partition operation with all previous
// operations.
@@ -2721,20 +2736,22 @@ void Win_GParted::activate_change_uuid()
}
// Make a duplicate of the selected partition (used in UNDO)
- Partition part_temp = *selected_partition_ptr;
+ Partition * part_temp = new Partition( *selected_partition_ptr );
- if ( part_temp .filesystem == GParted::FS_NTFS )
+ if ( part_temp->filesystem == FS_NTFS )
//Explicitly ask for half, so that the user will be aware of it
//Also, keep this kind of policy out of the NTFS code.
- part_temp .uuid = UUID_RANDOM_NTFS_HALF ;
+ part_temp->uuid = UUID_RANDOM_NTFS_HALF;
else
- part_temp .uuid = UUID_RANDOM ;
-
+ part_temp->uuid = UUID_RANDOM;
Operation * operation = new OperationChangeUUID( devices[current_device],
- *selected_partition_ptr, part_temp );
+ *selected_partition_ptr, *part_temp );
operation ->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
+ delete part_temp;
+ part_temp = NULL;
+
Add_Operation( operation ) ;
// Try to merge this change UUID operation with all previous operations.
merge_operations( MERGE_LAST_WITH_ANY );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]