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



commit 9b497aae144ae5bf429de3e3d7d50bc41be0f3e0
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Sep 26 12:33:28 2015 +0100

    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

 include/Operation.h    |    1 +
 src/Operation.cc       |   12 ++++++++++++
 src/OperationCreate.cc |   17 +++++++++++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/include/Operation.h b/include/Operation.h
index 4a81493..d89b957 100644
--- a/include/Operation.h
+++ b/include/Operation.h
@@ -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 );
 
diff --git a/src/Operation.cc b/src/Operation.cc
index b6484a3..a9c30f8 100644
--- a/src/Operation.cc
+++ b/src/Operation.cc
@@ -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++ )
diff --git a/src/OperationCreate.cc b/src/OperationCreate.cc
index 0a36355..af5dfa1 100644
--- a/src/OperationCreate.cc
+++ b/src/OperationCreate.cc
@@ -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 )
                {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]