Consolidate down to a single insert_unallocated() implementation (#759726)

GParted_Core and Operation classes both have an insert_unallocated()
method which do the same thing with very nearly identical code.  Both
methods insert unallocated partitions into the vector of partitions
within the specified range of sectors to fill in any gaps larger than
1 MiB.  The only difference was how the two methods got the device path;
the GParted_Core class method got it via a parameter and the Operation
class method got it by calling get_path() on its device member variable.
The GParted_Core insert_unallocated() method gets called during device
scanning and the Operation one gets called when constructing the visual
for a pending operation.

Consolidate down to a single insert_unallocated() implementation by
making the Operation class method call the GParted_Core class method.
Make the GParted_Core class method static and public so that it can be
called using the class name from outside the class.

Bug 759726 - Implement Partition object polymorphism
This commit is contained in:
Mike Fleetwood 2015-12-07 07:24:38 +00:00 committed by Curtis Gedak
parent fdbd86f1ea
commit 2a2a99b2bf
2 changed files with 10 additions and 53 deletions

View File

@ -67,6 +67,13 @@ public:
static FileSystem * get_filesystem_object( FILESYSTEM filesystem );
static bool supported_filesystem( FILESYSTEM fstype );
static bool filesystem_resize_disallowed( const Partition & partition ) ;
static void insert_unallocated( const Glib::ustring & device_path,
PartitionVector & partitions,
Sector start,
Sector end,
Byte_Value sector_size,
bool inside_extended );
private:
//detectionstuff..
static void init_maps() ;
@ -91,12 +98,6 @@ private:
std::vector<Glib::ustring> & messages );
void read_label( Partition & partition ) ;
void read_uuid( Partition & partition ) ;
void insert_unallocated( const Glib::ustring & device_path,
PartitionVector & partitions,
Sector start,
Sector end,
Byte_Value sector_size,
bool inside_extended );
void set_mountpoints( PartitionVector & partitions );
bool set_mountpoints_helper( Partition & partitions, const Glib::ustring & path ) ;
bool is_busy( FILESYSTEM fstype, const Glib::ustring & path ) ;

View File

@ -16,6 +16,7 @@
*/
#include "../include/Operation.h"
#include "../include/GParted_Core.h"
#include "../include/Partition.h"
#include "../include/PartitionVector.h"
@ -60,53 +61,8 @@ int Operation::find_index_extended( const PartitionVector & partitions )
void Operation::insert_unallocated( PartitionVector & partitions,
Sector start, Sector end, Byte_Value sector_size, bool inside_extended )
{
Partition UNALLOCATED ;
UNALLOCATED.Set_Unallocated( device.get_path(), false, 0LL, 0LL, sector_size, inside_extended );
//if there are no partitions at all..
if ( partitions .empty() )
{
UNALLOCATED .sector_start = start ;
UNALLOCATED .sector_end = end ;
partitions .push_back( UNALLOCATED );
return ;
}
//start <---> first partition start
if ( (partitions .front() .sector_start - start) > (MEBIBYTE / sector_size) )
{
UNALLOCATED .sector_start = start ;
UNALLOCATED .sector_end = partitions .front() .sector_start -1 ;
partitions .insert( partitions .begin(), UNALLOCATED );
}
//look for gaps in between
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ )
{
if ( ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) > (MEBIBYTE / sector_size) )
|| ( ( partitions[ t + 1 ] .type != TYPE_LOGICAL ) // Only show exactly 1 MiB if following partition is not logical.
&& ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) == (MEBIBYTE / sector_size) )
)
)
{
UNALLOCATED .sector_start = partitions[ t ] .sector_end +1 ;
UNALLOCATED .sector_end = partitions[ t +1 ] .sector_start -1 ;
partitions .insert( partitions .begin() + ++t, UNALLOCATED );
}
}
//last partition end <---> end
if ( (end - partitions .back() .sector_end ) >= (MEBIBYTE / sector_size) )
{
UNALLOCATED .sector_start = partitions .back() .sector_end +1 ;
UNALLOCATED .sector_end = end ;
partitions .push_back( UNALLOCATED );
}
GParted_Core::insert_unallocated( device.get_path(), partitions,
start, end, sector_size, inside_extended );
}
// Visual re-apply this operation, for operations which don't change the partition