Simplify Partition object to a single path (#767842)
Change from a vector of paths to a single path member in the Partition object. Remove add_paths() and get_paths() methods. Keep add_path() and get_path(). Bug 767842 - File system usage missing when tools report alternate block device names
This commit is contained in:
parent
1dc8a0c628
commit
214255eda3
|
@ -102,11 +102,9 @@ public:
|
||||||
void Update_Number( int new_number );
|
void Update_Number( int new_number );
|
||||||
|
|
||||||
void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
|
void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
|
||||||
void add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths = false ) ;
|
|
||||||
Byte_Value get_byte_length() const ;
|
Byte_Value get_byte_length() const ;
|
||||||
Sector get_sector_length() const ;
|
Sector get_sector_length() const ;
|
||||||
Glib::ustring get_path() const ;
|
Glib::ustring get_path() const ;
|
||||||
std::vector<Glib::ustring> get_paths() const ;
|
|
||||||
void add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints = false ) ;
|
void add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints = false ) ;
|
||||||
void add_mountpoints( const std::vector<Glib::ustring> & mountpoints, bool clear_mountpoints = false ) ;
|
void add_mountpoints( const std::vector<Glib::ustring> & mountpoints, bool clear_mountpoints = false ) ;
|
||||||
Glib::ustring get_mountpoint() const ;
|
Glib::ustring get_mountpoint() const ;
|
||||||
|
@ -169,12 +167,9 @@ private:
|
||||||
|
|
||||||
static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 ) ;
|
static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 ) ;
|
||||||
|
|
||||||
void sort_paths_and_remove_duplicates() ;
|
|
||||||
Sector calc_significant_unallocated_sectors() const ;
|
Sector calc_significant_unallocated_sectors() const ;
|
||||||
|
|
||||||
static bool compare_paths( const Glib::ustring & A, const Glib::ustring & B ) ;
|
Glib::ustring path;
|
||||||
|
|
||||||
std::vector<Glib::ustring> paths ;
|
|
||||||
std::vector<Glib::ustring> mountpoints ;
|
std::vector<Glib::ustring> mountpoints ;
|
||||||
bool have_filesystem_label;
|
bool have_filesystem_label;
|
||||||
Glib::ustring filesystem_label;
|
Glib::ustring filesystem_label;
|
||||||
|
|
|
@ -595,10 +595,10 @@ void Dialog_Partition_Info::Display_Info()
|
||||||
1, 2,
|
1, 2,
|
||||||
top, bottom,
|
top, bottom,
|
||||||
Gtk::FILL ) ;
|
Gtk::FILL ) ;
|
||||||
table ->attach( * Utils::mk_label( Glib::build_path( "\n", partition .get_paths() ), true, false, true ),
|
table->attach( * Utils::mk_label( partition.get_path(), true, false, true ),
|
||||||
2, 3,
|
2, 3,
|
||||||
top++, bottom++,
|
top++, bottom++,
|
||||||
Gtk::FILL ) ;
|
Gtk::FILL );
|
||||||
|
|
||||||
if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW )
|
if ( partition .type != GParted::TYPE_UNALLOCATED && partition .status != GParted::STAT_NEW )
|
||||||
{
|
{
|
||||||
|
|
|
@ -757,11 +757,11 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
|
||||||
if ( ! success )
|
if ( ! success )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Replace the new partition object's list of paths from the
|
// Replace the new partition object's path from the calibration in
|
||||||
// calibration in case the first path is "Copy of ..." from the
|
// case the path is "Copy of ..." from the partition having been
|
||||||
// partition having been newly created by a paste into unallocated
|
// newly created by a paste into unallocated space earlier in the
|
||||||
// space earlier in the sequence of operations now being applied.
|
// sequence of operations now being applied.
|
||||||
operation->get_partition_new().add_paths( operation->get_partition_original().get_paths(),
|
operation->get_partition_new().add_path( operation->get_partition_original().get_path(),
|
||||||
true );
|
true );
|
||||||
|
|
||||||
success = resize_move( operation->get_partition_original(),
|
success = resize_move( operation->get_partition_original(),
|
||||||
|
@ -774,11 +774,11 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
|
||||||
if ( ! success )
|
if ( ! success )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Replace the original partition object's list of paths from the
|
// Replace the original partition object's path from the
|
||||||
// calibration in case the first path is "Copy of ..." from the
|
// calibration in case the path is "Copy of ..." from the
|
||||||
// partition having been newly created by a paste into unallocated
|
// partition having been newly created by a paste into unallocated
|
||||||
// space earlier in the sequence of operations now being applied.
|
// space earlier in the sequence of operations now being applied.
|
||||||
operation->get_partition_original().add_paths( operation->get_partition_new().get_paths(),
|
operation->get_partition_original().add_path( operation->get_partition_new().get_path(),
|
||||||
true );
|
true );
|
||||||
|
|
||||||
success = remove_filesystem( operation->get_partition_original(),
|
success = remove_filesystem( operation->get_partition_original(),
|
||||||
|
@ -1235,7 +1235,6 @@ void GParted_Core::set_device_serial_number( Device & device )
|
||||||
void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk )
|
void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk )
|
||||||
{
|
{
|
||||||
int EXT_INDEX = -1 ;
|
int EXT_INDEX = -1 ;
|
||||||
Proc_Partitions_Info pp_info ; //Use cache of proc partitions information
|
|
||||||
#ifndef USE_LIBPARTED_DMRAID
|
#ifndef USE_LIBPARTED_DMRAID
|
||||||
DMRaid dmraid ; //Use cache of dmraid device information
|
DMRaid dmraid ; //Use cache of dmraid device information
|
||||||
#endif
|
#endif
|
||||||
|
@ -1310,7 +1309,7 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
|
||||||
( lp_partition->type == PED_PARTITION_LOGICAL ),
|
( lp_partition->type == PED_PARTITION_LOGICAL ),
|
||||||
partition_is_busy );
|
partition_is_busy );
|
||||||
partition_temp->append_messages( detect_messages );
|
partition_temp->append_messages( detect_messages );
|
||||||
partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
|
|
||||||
set_flags( *partition_temp, lp_partition );
|
set_flags( *partition_temp, lp_partition );
|
||||||
|
|
||||||
if ( filesystem == FS_LUKS )
|
if ( filesystem == FS_LUKS )
|
||||||
|
@ -1334,7 +1333,6 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
|
||||||
false,
|
false,
|
||||||
false );
|
false );
|
||||||
|
|
||||||
partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
|
|
||||||
set_flags( *partition_temp, lp_partition );
|
set_flags( *partition_temp, lp_partition );
|
||||||
|
|
||||||
EXT_INDEX = device .partitions .size() ;
|
EXT_INDEX = device .partitions .size() ;
|
||||||
|
@ -1399,8 +1397,6 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
|
||||||
void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
|
void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
|
||||||
std::vector<Glib::ustring> & messages )
|
std::vector<Glib::ustring> & messages )
|
||||||
{
|
{
|
||||||
Proc_Partitions_Info pp_info; // Use cache of proc partitions information
|
|
||||||
|
|
||||||
device.partitions.clear();
|
device.partitions.clear();
|
||||||
|
|
||||||
Glib::ustring path = lp_device->path;
|
Glib::ustring path = lp_device->path;
|
||||||
|
@ -1424,7 +1420,6 @@ void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_dev
|
||||||
partition_is_busy );
|
partition_is_busy );
|
||||||
|
|
||||||
partition_temp->append_messages( messages );
|
partition_temp->append_messages( messages );
|
||||||
partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
|
|
||||||
|
|
||||||
if ( fstype == FS_LUKS )
|
if ( fstype == FS_LUKS )
|
||||||
set_luks_partition( *dynamic_cast<PartitionLUKS *>( partition_temp ) );
|
set_luks_partition( *dynamic_cast<PartitionLUKS *>( partition_temp ) );
|
||||||
|
@ -1476,9 +1471,6 @@ void GParted_Core::set_luks_partition( PartitionLUKS & partition )
|
||||||
fs_busy );
|
fs_busy );
|
||||||
encrypted.append_messages( detect_messages );
|
encrypted.append_messages( detect_messages );
|
||||||
|
|
||||||
Proc_Partitions_Info pp_info; // Use cache of proc partitions information
|
|
||||||
encrypted.add_paths( pp_info.get_alternate_paths( encrypted.get_path() ) );
|
|
||||||
|
|
||||||
set_partition_label_and_uuid( encrypted );
|
set_partition_label_and_uuid( encrypted );
|
||||||
set_mountpoints( encrypted );
|
set_mountpoints( encrypted );
|
||||||
set_used_sectors( encrypted, NULL );
|
set_used_sectors( encrypted, NULL );
|
||||||
|
@ -1871,13 +1863,9 @@ void GParted_Core::set_mountpoints( Partition & partition )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Normal device, not DMRaid device
|
// Normal device, not DMRaid device
|
||||||
for ( unsigned int i = 0 ; i < partition.get_paths() .size() ; i++ )
|
if ( set_mountpoints_helper( partition, partition.get_path() ) )
|
||||||
{
|
|
||||||
Glib::ustring path = partition.get_paths()[i];
|
|
||||||
if ( set_mountpoints_helper( partition, path ) )
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( partition.get_mountpoints().empty() )
|
if ( partition.get_mountpoints().empty() )
|
||||||
partition.push_back_message( _("Unable to find mount point") );
|
partition.push_back_message( _("Unable to find mount point") );
|
||||||
|
|
|
@ -36,7 +36,7 @@ Partition * Partition::clone() const
|
||||||
|
|
||||||
void Partition::Reset()
|
void Partition::Reset()
|
||||||
{
|
{
|
||||||
paths .clear() ;
|
path.clear();
|
||||||
messages .clear() ;
|
messages .clear() ;
|
||||||
status = GParted::STAT_REAL ;
|
status = GParted::STAT_REAL ;
|
||||||
type = GParted::TYPE_UNALLOCATED ;
|
type = GParted::TYPE_UNALLOCATED ;
|
||||||
|
@ -71,9 +71,7 @@ void Partition::Set( const Glib::ustring & device_path,
|
||||||
bool busy )
|
bool busy )
|
||||||
{
|
{
|
||||||
this ->device_path = device_path ;
|
this ->device_path = device_path ;
|
||||||
|
this->path = partition;
|
||||||
paths .push_back( partition ) ;
|
|
||||||
|
|
||||||
this ->partition_number = partition_number;
|
this ->partition_number = partition_number;
|
||||||
this ->type = type;
|
this ->type = type;
|
||||||
this->whole_device = whole_device;
|
this->whole_device = whole_device;
|
||||||
|
@ -191,38 +189,18 @@ void Partition::Set_Unallocated( const Glib::ustring & device_path,
|
||||||
|
|
||||||
void Partition::Update_Number( int new_number )
|
void Partition::Update_Number( int new_number )
|
||||||
{
|
{
|
||||||
unsigned int index ;
|
unsigned int index = path.rfind( Utils::num_to_str( partition_number ) );
|
||||||
for ( unsigned int t = 0 ; t < paths .size() ; t++ )
|
if ( index < path.length() )
|
||||||
{
|
path.replace( index,
|
||||||
index = paths[ t ] .rfind( Utils::num_to_str( partition_number ) ) ;
|
Utils::num_to_str( partition_number ).length(),
|
||||||
|
Utils::num_to_str( new_number ) );
|
||||||
if ( index < paths[ t ] .length() )
|
|
||||||
paths[ t ] .replace( index,
|
|
||||||
Utils::num_to_str( partition_number ) .length(),
|
|
||||||
Utils::num_to_str( new_number ) ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
partition_number = new_number;
|
partition_number = new_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Partition::add_path( const Glib::ustring & path, bool clear_paths )
|
void Partition::add_path( const Glib::ustring & path, bool clear_paths )
|
||||||
{
|
{
|
||||||
if ( clear_paths )
|
this->path = path;
|
||||||
paths .clear() ;
|
|
||||||
|
|
||||||
paths .push_back( path ) ;
|
|
||||||
|
|
||||||
sort_paths_and_remove_duplicates() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Partition::add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths )
|
|
||||||
{
|
|
||||||
if ( clear_paths )
|
|
||||||
this ->paths .clear() ;
|
|
||||||
|
|
||||||
this ->paths .insert( this ->paths .end(), paths .begin(), paths .end() ) ;
|
|
||||||
|
|
||||||
sort_paths_and_remove_duplicates() ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte_Value Partition::get_byte_length() const
|
Byte_Value Partition::get_byte_length() const
|
||||||
|
@ -243,15 +221,7 @@ Sector Partition::get_sector_length() const
|
||||||
|
|
||||||
Glib::ustring Partition::get_path() const
|
Glib::ustring Partition::get_path() const
|
||||||
{
|
{
|
||||||
if ( paths .size() > 0 )
|
return path;
|
||||||
return paths .front() ;
|
|
||||||
|
|
||||||
return "" ;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Glib::ustring> Partition::get_paths() const
|
|
||||||
{
|
|
||||||
return paths ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Partition::filesystem_label_known() const
|
bool Partition::filesystem_label_known() const
|
||||||
|
@ -338,16 +308,6 @@ void Partition::get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Partition::sort_paths_and_remove_duplicates()
|
|
||||||
{
|
|
||||||
//remove duplicates
|
|
||||||
std::sort( paths .begin(), paths .end() ) ;
|
|
||||||
paths .erase( std::unique( paths .begin(), paths .end() ), paths .end() ) ;
|
|
||||||
|
|
||||||
//sort on length
|
|
||||||
std::sort( paths .begin(), paths .end(), compare_paths ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Partition::add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints )
|
void Partition::add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints )
|
||||||
{
|
{
|
||||||
if ( clear_mountpoints )
|
if ( clear_mountpoints )
|
||||||
|
@ -396,11 +356,6 @@ void Partition::clear_mountpoints()
|
||||||
mountpoints .clear() ;
|
mountpoints .clear() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Partition::compare_paths( const Glib::ustring & A, const Glib::ustring & B )
|
|
||||||
{
|
|
||||||
return A .length() < B .length() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return threshold of sectors which is considered above the intrinsic
|
//Return threshold of sectors which is considered above the intrinsic
|
||||||
// level for a file system which "fills" the partition. Calculation
|
// level for a file system which "fills" the partition. Calculation
|
||||||
// is:
|
// is:
|
||||||
|
|
Loading…
Reference in New Issue