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:
parent
fdbd86f1ea
commit
2a2a99b2bf
|
@ -67,6 +67,13 @@ public:
|
||||||
static FileSystem * get_filesystem_object( FILESYSTEM filesystem );
|
static FileSystem * get_filesystem_object( FILESYSTEM filesystem );
|
||||||
static bool supported_filesystem( FILESYSTEM fstype );
|
static bool supported_filesystem( FILESYSTEM fstype );
|
||||||
static bool filesystem_resize_disallowed( const Partition & partition ) ;
|
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:
|
private:
|
||||||
//detectionstuff..
|
//detectionstuff..
|
||||||
static void init_maps() ;
|
static void init_maps() ;
|
||||||
|
@ -91,12 +98,6 @@ private:
|
||||||
std::vector<Glib::ustring> & messages );
|
std::vector<Glib::ustring> & messages );
|
||||||
void read_label( Partition & partition ) ;
|
void read_label( Partition & partition ) ;
|
||||||
void read_uuid( 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 );
|
void set_mountpoints( PartitionVector & partitions );
|
||||||
bool set_mountpoints_helper( Partition & partitions, const Glib::ustring & path ) ;
|
bool set_mountpoints_helper( Partition & partitions, const Glib::ustring & path ) ;
|
||||||
bool is_busy( FILESYSTEM fstype, const Glib::ustring & path ) ;
|
bool is_busy( FILESYSTEM fstype, const Glib::ustring & path ) ;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../include/Operation.h"
|
#include "../include/Operation.h"
|
||||||
|
#include "../include/GParted_Core.h"
|
||||||
#include "../include/Partition.h"
|
#include "../include/Partition.h"
|
||||||
#include "../include/PartitionVector.h"
|
#include "../include/PartitionVector.h"
|
||||||
|
|
||||||
|
@ -60,53 +61,8 @@ int Operation::find_index_extended( const PartitionVector & partitions )
|
||||||
void Operation::insert_unallocated( PartitionVector & partitions,
|
void Operation::insert_unallocated( PartitionVector & partitions,
|
||||||
Sector start, Sector end, Byte_Value sector_size, bool inside_extended )
|
Sector start, Sector end, Byte_Value sector_size, bool inside_extended )
|
||||||
{
|
{
|
||||||
Partition UNALLOCATED ;
|
GParted_Core::insert_unallocated( device.get_path(), partitions,
|
||||||
UNALLOCATED.Set_Unallocated( device.get_path(), false, 0LL, 0LL, sector_size, inside_extended );
|
start, end, 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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visual re-apply this operation, for operations which don't change the partition
|
// Visual re-apply this operation, for operations which don't change the partition
|
||||||
|
|
Loading…
Reference in New Issue