Refactor GParted_Core::move() (#775932)

Simplify the move() function.  Change it into an if-operation-fails-
return-false style and re-write the final overly complicated conditional
check repair and maximise file system.

The final condition said if the file system was linux-swap or the new
partition was larger, perform a check repair and maximize file system.
However this is a move only step with a check at the top of the move()
function ensuring the Partition objects are the same size.  So that
simplifies to only checking for linux-swap.  As the context is a move
and linux-swap is recreated, performing a check repair first is
unnecessary, so remove that too.

Bug 775932 - Refactor mostly applying of operations
This commit is contained in:
Mike Fleetwood 2016-11-19 10:36:06 +00:00 committed by Curtis Gedak
parent 7caebd2515
commit d2fad35407

View file

@ -2284,16 +2284,16 @@ bool GParted_Core::move( const Partition & partition_old,
return false ; return false ;
} }
bool succes = false ; if ( ! check_repair_filesystem( partition_old, operationdetail ) )
if ( check_repair_filesystem( partition_old, operationdetail ) ) return false;
{
//NOTE: Logical partitions are preceded by meta data. To prevent this // NOTE:
// meta data from being overwritten we first expand the partition to // Logical partitions are preceded by meta data. To prevent this meta data from
// encompass all of the space involved in the move. In this way we // being overwritten we first expand the partition to encompass all of the space
// prevent overwriting the meta data for this partition when we move // involved in the move. In this way we prevent overwriting the meta data for
// this partition to the left. We also prevent overwriting the meta // this partition when we move this partition to the left. We also prevent
// data of a following partition when we move this partition to the // overwriting the meta data of a following partition when we move this partition
// right. // to the right.
Partition * partition_all_space = partition_old.clone(); Partition * partition_all_space = partition_old.clone();
partition_all_space->alignment = ALIGN_STRICT; partition_all_space->alignment = ALIGN_STRICT;
if ( partition_new.sector_start < partition_all_space->sector_start ) if ( partition_new.sector_start < partition_all_space->sector_start )
@ -2301,56 +2301,58 @@ bool GParted_Core::move( const Partition & partition_old,
if ( partition_new.sector_end > partition_all_space->sector_end ) if ( partition_new.sector_end > partition_all_space->sector_end )
partition_all_space->sector_end = partition_new.sector_end; partition_all_space->sector_end = partition_new.sector_end;
//Make old partition all encompassing and if move file system fails // Make old partition all encompassing and if move file system fails then return
// then return partition table to original state // partition table to original state
bool success = false;
if ( resize_move_partition( partition_old, *partition_all_space, operationdetail ) ) if ( resize_move_partition( partition_old, *partition_all_space, operationdetail ) )
{ {
//Note move of file system is from old values to new values, not from // Note move of file system is from old values to new values, not from the
// the all encompassing values. // all encompassing values.
if ( ! move_filesystem( partition_old, partition_new, operationdetail ) ) if ( ! move_filesystem( partition_old, partition_new, operationdetail ) )
{ {
operationdetail .add_child( OperationDetail( _("rollback last change to the partition table") ) ) ; operationdetail.add_child( OperationDetail(
_("rollback last change to the partition table") ) );
Partition * partition_restore = partition_old.clone(); Partition * partition_restore = partition_old.clone();
partition_restore->alignment = ALIGN_STRICT; // Ensure that old partition boundaries are not modified partition_restore->alignment = ALIGN_STRICT; // Ensure that old partition boundaries are not modified
if ( resize_move_partition( if ( resize_move_partition( *partition_all_space,
*partition_all_space, *partition_restore, operationdetail.get_last_child() ) ) *partition_restore, operationdetail.get_last_child() ) )
{ {
operationdetail.get_last_child().set_status( STATUS_SUCCES ); operationdetail.get_last_child().set_status( STATUS_SUCCES );
check_repair_filesystem( partition_old, operationdetail ); check_repair_filesystem( partition_old, operationdetail );
} }
else else
{
operationdetail.get_last_child().set_status( STATUS_ERROR ); operationdetail.get_last_child().set_status( STATUS_ERROR );
}
delete partition_restore; delete partition_restore;
partition_restore = NULL; partition_restore = NULL;
} }
else else
succes = true ; {
success = true;
}
} }
// Make new partition from all encompassing partition // Make new partition from all encompassing partition
succes = succes && resize_move_partition( *partition_all_space, partition_new, operationdetail ); if ( success )
{
success = resize_move_partition( *partition_all_space, partition_new, operationdetail )
&& update_bootsector( partition_new, operationdetail );
}
delete partition_all_space; delete partition_all_space;
partition_all_space = NULL; partition_all_space = NULL;
succes = ( succes if ( ! success )
&& update_bootsector( partition_new, operationdetail ) return false;
&& ( //Do not maximize file system if FS not linux-swap and new size <= old
( partition_new .filesystem != FS_LINUX_SWAP //linux-swap is recreated, not moved
&& partition_new .get_sector_length() <= partition_old .get_sector_length()
)
|| ( check_repair_filesystem( partition_new, operationdetail )
&& maximize_filesystem( partition_new, operationdetail )
)
)
);
} if ( partition_new.filesystem == FS_LINUX_SWAP )
// linux-swap is recreated, not moved
return maximize_filesystem( partition_new, operationdetail );
return succes ; return true;
} }
bool GParted_Core::move_filesystem( const Partition & partition_old, bool GParted_Core::move_filesystem( const Partition & partition_old,