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
This commit is contained in:
parent
ea8ab702f7
commit
4d8578646c
|
@ -2399,29 +2399,34 @@ bool GParted_Core::resize_move( const Partition & partition_old,
|
||||||
return resize( partition_old, partition_new, operationdetail ) ;
|
return resize( partition_old, partition_new, operationdetail ) ;
|
||||||
|
|
||||||
if ( partition_new .get_sector_length() == partition_old .get_sector_length() )
|
if ( partition_new .get_sector_length() == partition_old .get_sector_length() )
|
||||||
|
{
|
||||||
return move( partition_old, partition_new, operationdetail );
|
return move( partition_old, partition_new, operationdetail );
|
||||||
|
}
|
||||||
Partition temp ;
|
Partition * temp = NULL;
|
||||||
if ( partition_new .get_sector_length() > partition_old .get_sector_length() )
|
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.
|
//first move, then grow. Since old.length < new.length and new.start is valid, temp is valid.
|
||||||
temp = partition_new ;
|
temp = new Partition( partition_new );
|
||||||
temp .sector_end = temp .sector_start + partition_old .get_sector_length() -1 ;
|
temp->sector_end = temp->sector_start + partition_old.get_sector_length() - 1;
|
||||||
}
|
}
|
||||||
|
else // ( partition_new.get_sector_length() < partition_old.get_sector_length() )
|
||||||
if ( 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.
|
//first shrink, then move. Since new.length < old.length and old.start is valid, temp is valid.
|
||||||
temp = partition_old ;
|
temp = new Partition( partition_old );
|
||||||
temp .sector_end = partition_old .sector_start + partition_new .get_sector_length() -1 ;
|
temp->sector_end = partition_old.sector_start + partition_new.get_sector_length() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionAlignment previous_alignment = temp .alignment ;
|
PartitionAlignment previous_alignment = temp->alignment;
|
||||||
temp .alignment = ALIGN_STRICT ;
|
temp->alignment = ALIGN_STRICT;
|
||||||
bool succes = resize_move( partition_old, temp, operationdetail );
|
bool success = resize_move( partition_old, *temp, operationdetail );
|
||||||
temp .alignment = previous_alignment ;
|
temp->alignment = previous_alignment;
|
||||||
|
if ( success )
|
||||||
|
success = resize_move( *temp, partition_new, operationdetail );
|
||||||
|
|
||||||
return succes && resize_move( temp, partition_new, operationdetail );
|
delete temp;
|
||||||
|
temp = NULL;
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
|
@ -3191,32 +3196,43 @@ void GParted_Core::rollback_transaction( const Partition & partition_src,
|
||||||
if ( total_done > 0 )
|
if ( total_done > 0 )
|
||||||
{
|
{
|
||||||
//find out exactly which part of the file system was copied (and to where it was copied)..
|
//find out exactly which part of the file system was copied (and to where it was copied)..
|
||||||
Partition temp_src = partition_src ;
|
Partition * temp_src = new Partition( partition_src );
|
||||||
Partition temp_dst = partition_dst ;
|
Partition * temp_dst = new Partition( partition_dst );
|
||||||
|
bool rollback_needed = true;
|
||||||
|
|
||||||
if ( partition_dst .sector_start > partition_src .sector_start )
|
if ( partition_dst .sector_start > partition_src .sector_start )
|
||||||
{
|
{
|
||||||
Sector distance = 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_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;
|
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)
|
if ( temp_src->sector_start > temp_src->sector_end )
|
||||||
return; /* nothing has been overwritten yet, so nothing to roll back */
|
// Nothing has been overwritten yet, so nothing to roll back
|
||||||
|
rollback_needed = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Sector distance = partition_src.sector_start - partition_dst.sector_start;
|
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_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;
|
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)
|
if ( temp_src->sector_start > temp_src->sector_end )
|
||||||
return; /* nothing has been overwritten yet, so nothing to roll back */
|
// 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)
|
if ( rollback_needed )
|
||||||
bool succes = copy_filesystem( temp_dst, temp_src, operationdetail .get_last_child(), false ) ;
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1741,7 +1741,8 @@ void Win_GParted::activate_resize()
|
||||||
{
|
{
|
||||||
dialog .hide() ;
|
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
|
// When resizing/moving a partition which already exists on the disk all
|
||||||
// possible operations could be pending so only try merging with the
|
// possible operations could be pending so only try merging with the
|
||||||
// previous operation.
|
// previous operation.
|
||||||
|
@ -1751,7 +1752,7 @@ void Win_GParted::activate_resize()
|
||||||
// it again with the new size and position ( unless it's an EXTENDED )
|
// 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 )
|
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
|
// On a partition which is pending creation only resize/move and
|
||||||
// format operations are possible. These operations are always
|
// format operations are possible. These operations are always
|
||||||
// mergeable with the pending operation which will create the
|
// 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],
|
Operation * operation = new OperationResizeMove( devices[current_device],
|
||||||
*selected_partition_ptr,
|
*selected_partition_ptr,
|
||||||
part_temp );
|
*part_temp );
|
||||||
operation->icon = render_icon( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU );
|
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
|
// Display warning if moving a non-extended partition which already exists
|
||||||
// on the disk.
|
// on the disk.
|
||||||
if ( operation->get_partition_original().status != STAT_NEW &&
|
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
|
// We don't want the messages, mount points or name of the source
|
||||||
// partition for the new partition being created.
|
// partition for the new partition being created.
|
||||||
Partition part_temp = *copied_partition;
|
Partition * part_temp = new Partition( *copied_partition );
|
||||||
part_temp.messages.clear();
|
part_temp->messages.clear();
|
||||||
part_temp.clear_mountpoints();
|
part_temp->clear_mountpoints();
|
||||||
part_temp.name.clear();
|
part_temp->name.clear();
|
||||||
|
|
||||||
Dialog_Partition_Copy dialog( gparted_core.get_fs( copied_partition->filesystem ),
|
Dialog_Partition_Copy dialog( gparted_core.get_fs( copied_partition->filesystem ),
|
||||||
*selected_partition_ptr,
|
*selected_partition_ptr,
|
||||||
part_temp );
|
*part_temp );
|
||||||
|
delete part_temp;
|
||||||
|
part_temp = NULL;
|
||||||
dialog .set_transient_for( *this );
|
dialog .set_transient_for( *this );
|
||||||
|
|
||||||
if ( dialog .run() == Gtk::RESPONSE_OK )
|
if ( dialog .run() == Gtk::RESPONSE_OK )
|
||||||
|
@ -1864,19 +1870,19 @@ void Win_GParted::activate_paste()
|
||||||
shown_dialog = true ;
|
shown_dialog = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Partition partition_new = *selected_partition_ptr;
|
Partition * partition_new = new Partition( *selected_partition_ptr );
|
||||||
partition_new .alignment = ALIGN_STRICT ;
|
partition_new->alignment = ALIGN_STRICT;
|
||||||
partition_new.filesystem = copied_partition->filesystem;
|
partition_new->filesystem = copied_partition->filesystem;
|
||||||
partition_new.set_filesystem_label( copied_partition->get_filesystem_label() );
|
partition_new->set_filesystem_label( copied_partition->get_filesystem_label() );
|
||||||
partition_new.uuid = copied_partition->uuid;
|
partition_new->uuid = copied_partition->uuid;
|
||||||
partition_new.color = copied_partition->color;
|
partition_new->color = copied_partition->color;
|
||||||
Sector new_size = partition_new .get_sector_length() ;
|
Sector new_size = partition_new->get_sector_length();
|
||||||
if ( copied_partition->get_sector_length() == new_size )
|
if ( copied_partition->get_sector_length() == new_size )
|
||||||
{
|
{
|
||||||
// Pasting into same size existing partition, therefore only block
|
// Pasting into same size existing partition, therefore only block
|
||||||
// copy operation will be performed maintaining the file system
|
// copy operation will be performed maintaining the file system
|
||||||
// size.
|
// size.
|
||||||
partition_new .set_sector_usage(
|
partition_new->set_sector_usage(
|
||||||
copied_partition->sectors_used + copied_partition->sectors_unused,
|
copied_partition->sectors_used + copied_partition->sectors_unused,
|
||||||
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
|
// Pasting into larger existing partition, therefore block copy
|
||||||
// followed by file system grow operations (if supported) will be
|
// followed by file system grow operations (if supported) will be
|
||||||
// performed making the file system fill the partition.
|
// performed making the file system fill the partition.
|
||||||
partition_new .set_sector_usage(
|
partition_new->set_sector_usage(
|
||||||
new_size,
|
new_size,
|
||||||
new_size - copied_partition->sectors_used );
|
new_size - copied_partition->sectors_used );
|
||||||
}
|
}
|
||||||
partition_new .messages .clear() ;
|
partition_new->messages.clear();
|
||||||
|
|
||||||
Operation * operation = new OperationCopy( devices[current_device],
|
Operation * operation = new OperationCopy( devices[current_device],
|
||||||
*selected_partition_ptr,
|
*selected_partition_ptr,
|
||||||
partition_new,
|
*partition_new,
|
||||||
*copied_partition );
|
*copied_partition );
|
||||||
operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU );
|
operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU );
|
||||||
|
|
||||||
|
delete partition_new;
|
||||||
|
partition_new = NULL;
|
||||||
|
|
||||||
Add_Operation( operation ) ;
|
Add_Operation( operation ) ;
|
||||||
|
|
||||||
if ( ! shown_dialog )
|
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. */
|
/*TO TRANSLATORS: looks like The data in /dev/sda3 will be lost if you apply this operation. */
|
||||||
dialog .set_secondary_text(
|
dialog .set_secondary_text(
|
||||||
String::ucompose( _( "The data in %1 will be lost if you apply this operation." ),
|
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() ;
|
dialog .run() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2646,14 +2655,17 @@ void Win_GParted::activate_label_filesystem()
|
||||||
{
|
{
|
||||||
dialog .hide() ;
|
dialog .hide() ;
|
||||||
// Make a duplicate of the selected partition (used in UNDO)
|
// 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],
|
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 );
|
operation ->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
|
||||||
|
|
||||||
|
delete part_temp;
|
||||||
|
part_temp = NULL;
|
||||||
|
|
||||||
Add_Operation( operation ) ;
|
Add_Operation( operation ) ;
|
||||||
// Try to merge this label file system operation with all previous
|
// Try to merge this label file system operation with all previous
|
||||||
// operations.
|
// operations.
|
||||||
|
@ -2677,14 +2689,17 @@ void Win_GParted::activate_name_partition()
|
||||||
{
|
{
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
// Make a duplicate of the selected partition (used in UNDO)
|
// 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],
|
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 );
|
operation->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
|
||||||
|
|
||||||
|
delete part_temp;
|
||||||
|
part_temp = NULL;
|
||||||
|
|
||||||
Add_Operation( operation );
|
Add_Operation( operation );
|
||||||
// Try to merge this name partition operation with all previous
|
// Try to merge this name partition operation with all previous
|
||||||
// operations.
|
// operations.
|
||||||
|
@ -2721,20 +2736,22 @@ void Win_GParted::activate_change_uuid()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a duplicate of the selected partition (used in UNDO)
|
// 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
|
//Explicitly ask for half, so that the user will be aware of it
|
||||||
//Also, keep this kind of policy out of the NTFS code.
|
//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
|
else
|
||||||
part_temp .uuid = UUID_RANDOM ;
|
part_temp->uuid = UUID_RANDOM;
|
||||||
|
|
||||||
|
|
||||||
Operation * operation = new OperationChangeUUID( devices[current_device],
|
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 );
|
operation ->icon = render_icon( Gtk::Stock::EXECUTE, Gtk::ICON_SIZE_MENU );
|
||||||
|
|
||||||
|
delete part_temp;
|
||||||
|
part_temp = NULL;
|
||||||
|
|
||||||
Add_Operation( operation ) ;
|
Add_Operation( operation ) ;
|
||||||
// Try to merge this change UUID operation with all previous operations.
|
// Try to merge this change UUID operation with all previous operations.
|
||||||
merge_operations( MERGE_LAST_WITH_ANY );
|
merge_operations( MERGE_LAST_WITH_ANY );
|
||||||
|
|
Loading…
Reference in New Issue