Refactor resize() to make it even easier to understand (#741211)

Split the resizing file system and resizing partition calls in
GParted_Core::resize() into separate grow and shrink code paths.

Note that this also changes the degenerative case of calling resize()
when the partition isn't changing size, for non-swap partitions, from a
file system check step to a successful no-op.  This doesn't matter as my
testing never found resize() to be called when the partition isn't
changing size.

Also correct spelling of local variable success.

Bug 741211 - Remove unnecessary duplicate actions when resizing a
             partition
This commit is contained in:
Mike Fleetwood 2014-12-07 11:08:56 +00:00 committed by Curtis Gedak
parent 99f770ddb0
commit 95ff4fbdc9
1 changed files with 17 additions and 19 deletions

View File

@ -2388,33 +2388,31 @@ bool GParted_Core::resize( const Partition & partition_old,
return false ;
}
bool succes = false ;
bool success = true;
if ( partition_new.filesystem == FS_LINUX_SWAP )
{
// linux-swap is recreated, not resize
succes = resize_move_partition( partition_old, partition_new, operationdetail )
&& resize_filesystem( partition_old, partition_new, operationdetail );
success = resize_move_partition( partition_old, partition_new, operationdetail )
&& resize_filesystem( partition_old, partition_new, operationdetail );
return succes;
return success;
}
else if ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail ) )
Sector delta = partition_new.get_sector_length() - partition_old.get_sector_length();
if ( delta < 0LL ) // shrink
{
succes = true ;
if ( succes && partition_new .get_sector_length() < partition_old .get_sector_length() )
succes = resize_filesystem( partition_old, partition_new, operationdetail ) ;
if ( succes )
succes = resize_move_partition( partition_old, partition_new, operationdetail ) ;
// Maximize file system if growing
if ( succes && partition_new .get_sector_length() > partition_old .get_sector_length() )
succes = maximize_filesystem( partition_new, operationdetail );
return succes ;
success = ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail ) )
&& resize_filesystem( partition_old, partition_new, operationdetail )
&& resize_move_partition( partition_old, partition_new, operationdetail );
}
else if ( delta > 0LL ) // grow
{
success = ( partition_new.busy || check_repair_filesystem( partition_new, operationdetail ) )
&& resize_move_partition( partition_old, partition_new, operationdetail )
&& maximize_filesystem( partition_new, operationdetail );
}
return false ;
return success;
}
bool GParted_Core::resize_move_partition( const Partition & partition_old,