[gparted] Share duplicate code substituting partitions in multiple operations (#755214)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Share duplicate code substituting partitions in multiple operations (#755214)
- Date: Tue, 29 Sep 2015 18:43:14 +0000 (UTC)
commit 27cbe36d0f4c33ada81527d7ec97cc92bf315475
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sat Sep 26 14:25:58 2015 +0100
Share duplicate code substituting partitions in multiple operations (#755214)
The apply_to_visual() method for the change UUID, format, label file
system and name partition operations duplicated identical code. This
code was just substituting the partition in the disk graphic vector with
the new partition recorded in the operation, as none of these operations
change the partition boundaries. Move this duplicate code into the
parent class in new method Operation::substitute_new().
Bug 755214 - Refactor operation merging
include/Operation.h | 1 +
src/Operation.cc | 23 +++++++++++++++++++++++
src/OperationChangeUUID.cc | 18 +-----------------
src/OperationFormat.cc | 15 +--------------
src/OperationLabelFileSystem.cc | 18 +-----------------
src/OperationNamePartition.cc | 18 +-----------------
6 files changed, 28 insertions(+), 65 deletions(-)
---
diff --git a/include/Operation.h b/include/Operation.h
index d89b957..26ae43d 100644
--- a/include/Operation.h
+++ b/include/Operation.h
@@ -63,6 +63,7 @@ protected:
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 );
+ void substitute_new( std::vector<Partition> & partitions );
int index ;
int index_extended ;
diff --git a/src/Operation.cc b/src/Operation.cc
index a9c30f8..e55dab5 100644
--- a/src/Operation.cc
+++ b/src/Operation.cc
@@ -105,4 +105,27 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
}
}
+// Visual re-apply this operation, for operations which don't change the partition
+// boundaries. Matches this operation's original partition in the vector and substitutes
+// it with this operation's new partition.
+void Operation::substitute_new( std::vector<Partition> & partitions )
+{
+ if ( partition_original.inside_extended )
+ {
+ index_extended = find_index_extended( partitions );
+ if ( index_extended >= 0 )
+ {
+ index = find_index_original( partitions[index_extended].logicals );
+ if ( index >= 0 )
+ partitions[index_extended].logicals[index] = partition_new;
+ }
+ }
+ else
+ {
+ index = find_index_original( partitions );
+ if ( index >= 0 )
+ partitions[index] = partition_new;
+ }
+}
+
} //GParted
diff --git a/src/OperationChangeUUID.cc b/src/OperationChangeUUID.cc
index e05d404..e01482f 100644
--- a/src/OperationChangeUUID.cc
+++ b/src/OperationChangeUUID.cc
@@ -33,23 +33,7 @@ OperationChangeUUID::OperationChangeUUID( const Device & device
void OperationChangeUUID::apply_to_visual( std::vector<Partition> & partitions )
{
- if ( partition_original .inside_extended )
- {
- index_extended = find_index_extended( partitions ) ;
-
- if ( index_extended >= 0 )
- index = find_index_original( partitions[ index_extended ] .logicals ) ;
-
- if ( index >= 0 )
- partitions[ index_extended ] .logicals[ index ] = partition_new ;
- }
- else
- {
- index = find_index_original( partitions ) ;
-
- if ( index >= 0 )
- partitions[ index ] = partition_new ;
- }
+ substitute_new( partitions );
}
void OperationChangeUUID::create_description()
diff --git a/src/OperationFormat.cc b/src/OperationFormat.cc
index 3df797d..04db2cb 100644
--- a/src/OperationFormat.cc
+++ b/src/OperationFormat.cc
@@ -47,22 +47,9 @@ void OperationFormat::apply_to_visual( std::vector<Partition> & partitions )
false );
partitions.push_back( temp_partition );
}
- else if ( partition_original.inside_extended )
- {
- index_extended = find_index_extended( partitions ) ;
-
- if ( index_extended >= 0 )
- index = find_index_original( partitions[ index_extended ] .logicals ) ;
-
- if ( index >= 0 )
- partitions[ index_extended ] .logicals[ index ] = partition_new ;
- }
else
{
- index = find_index_original( partitions ) ;
-
- if ( index >= 0 )
- partitions[ index ] = partition_new ;
+ substitute_new( partitions );
}
}
diff --git a/src/OperationLabelFileSystem.cc b/src/OperationLabelFileSystem.cc
index 9a07426..9d750bd 100644
--- a/src/OperationLabelFileSystem.cc
+++ b/src/OperationLabelFileSystem.cc
@@ -32,23 +32,7 @@ OperationLabelFileSystem::OperationLabelFileSystem( const Device & device,
void OperationLabelFileSystem::apply_to_visual( std::vector<Partition> & partitions )
{
- if ( partition_original .inside_extended )
- {
- index_extended = find_index_extended( partitions ) ;
-
- if ( index_extended >= 0 )
- index = find_index_original( partitions[ index_extended ] .logicals ) ;
-
- if ( index >= 0 )
- partitions[ index_extended ] .logicals[ index ] = partition_new ;
- }
- else
- {
- index = find_index_original( partitions ) ;
-
- if ( index >= 0 )
- partitions[ index ] = partition_new ;
- }
+ substitute_new( partitions );
}
void OperationLabelFileSystem::create_description()
diff --git a/src/OperationNamePartition.cc b/src/OperationNamePartition.cc
index 84aca51..e352cd7 100644
--- a/src/OperationNamePartition.cc
+++ b/src/OperationNamePartition.cc
@@ -32,23 +32,7 @@ OperationNamePartition::OperationNamePartition( const Device & device,
void OperationNamePartition::apply_to_visual( std::vector<Partition> & partitions )
{
- if ( partition_original.inside_extended )
- {
- index_extended = find_index_extended( partitions );
-
- if ( index_extended >= 0 )
- index = find_index_original( partitions[index_extended].logicals );
-
- if ( index >= 0 )
- partitions[index_extended].logicals[index] = partition_new;
- }
- else
- {
- index = find_index_original( partitions );
-
- if ( index >= 0 )
- partitions[index] = partition_new;
- }
+ substitute_new( partitions );
}
void OperationNamePartition::create_description()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]