Fix visually re-applying create operation in create-create-grow-first sequence (#755214)

After previous commit "Replace open coded merge of resize/move into
create operation (#755214)" the second created partition would disappear
from the disk graphic in the following sequence: create new #1, create
new #2 leaving space preceding, resize #1 larger.  The create new #2
operation still existed and was shown in the operation list.  It was
just that it disappeared from the disk graphic.

Remember that when each operation is created it records the partition,
or the unallocated space, to which the operation is applied at the time
the operation is created in the partition_original member variable.  In
the above sequence the resize #1 larger operation was merged back into
the create new #1 operation.  When visually re-applying the create
new #1 operation to the disk graphic, it left a smaller unallocated
partition following it.  This was smaller than the unallocated partition
recorded in the create new #2 operation, hence it failed to visually
re-apply to the disk graphic.

The insight to fix this is that it doesn't matter what size the
unallocated space was when the create new operation was constructed.  It
only matters that the new partition to be created fits in the available
unallocated space currently in the disk graphic.

Bug 755214 - Refactor operation merging
This commit is contained in:
Mike Fleetwood 2015-09-26 12:33:28 +01:00 committed by Curtis Gedak
parent 27e5bbeece
commit 9b497aae14
3 changed files with 26 additions and 4 deletions

View File

@ -60,6 +60,7 @@ public:
protected:
int find_index_original( const std::vector<Partition> & partitions ) ;
int find_index_new( const std::vector<Partition> & partitions );
int find_index_extended( const std::vector<Partition> & partitions ) ;
void insert_unallocated( std::vector<Partition> & partitions, Sector start, Sector end, Byte_Value sector_size, bool inside_extended );

View File

@ -33,6 +33,18 @@ int Operation::find_index_original( const std::vector<Partition> & partitions )
return -1 ;
}
// Find the partition in the vector that exactly matches or fully encloses
// this->partition_new. Return vector index or -1 when no match found.
int Operation::find_index_new( const std::vector<Partition> & partitions )
{
for ( unsigned int i = 0 ; i < partitions.size() ; i ++ )
if ( partition_new.sector_start >= partitions[i].sector_start &&
partition_new.sector_end <= partitions[i].sector_end )
return i;
return -1;
}
int Operation::find_index_extended( const std::vector<Partition> & partitions )
{
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )

View File

@ -33,15 +33,24 @@ OperationCreate::OperationCreate( const Device & device,
void OperationCreate::apply_to_visual( std::vector<Partition> & partitions )
{
// Create operations are unique in that they apply to unallocated space. It only
// matters that the new partition being created fits in an unallocated space when
// visually re-applying this operation to the disk graphic. Hence the use of,
// find_index_new() below.
//
// All other operation types apply to existing partitions which do or will exist
// on disk. Therefore they match the original partition when visually re-applying
// their operations to the disk graphic. Hence their use of,
// find_index_original().
index = index_extended = -1 ;
if ( partition_original .inside_extended )
if ( partition_new.inside_extended )
{
index_extended = find_index_extended( partitions ) ;
if ( index_extended >= 0 )
index = find_index_original( partitions[ index_extended ] .logicals ) ;
index = find_index_new( partitions[index_extended].logicals );
if ( index >= 0 )
{
partitions[ index_extended ] .logicals[ index ] = partition_new ;
@ -55,7 +64,7 @@ void OperationCreate::apply_to_visual( std::vector<Partition> & partitions )
}
else
{
index = find_index_original( partitions ) ;
index = find_index_new( partitions );
if ( index >= 0 )
{