Simplify Device object to a single path (#767842)

Background

GParted stored a list of paths for Device and Partition objects.  It
sorted this list [1][2] and treated the first specially as that is what
get_path() returned and was used almost everywhere; with the file system
specific tools, looked up in various *_Info caches, etc.

[1] Device::add_path(), ::add_paths()
[2] Partition::add_path(), ::add_paths()

Mount point display [3] was the only bit of GParted which really worked
with the path list.  Busy file system detection [4] just used the path
provided by libparted, or for LUKS /dev/mapper/* names.  It checked that
single path against the mounted file systems found from /proc/mounts,
expanded with additional block device names when symlinks were
encountered.

[3] GParted_Core::set_mountpoints() -> set_mountpoints_helper()
[4] GParted_Core::set_device_partitions() -> is_busy()
    GParted_Core::set_device_one_partition() -> is_busy()
    GParted_Core::set_luks_partition() -> is_busy()

Having the first path, by sort order, treated specially by being used
everywhere and virtually ignoring the others was wrong, complicated to
remember and difficult code with.  As all the additional paths were
virtually unused and made no difference, remove them.  The "improved
detection of mountpoins, free space, etc.." benefit from commit [5]
doesn't seem to exist.  Therefore simplify to a single path for Device
and Partition objects.

[5] commit 6d8b169e73
    changed the way devices and partitions store their device paths.
    Instead of holding a 'realpath' and a symbolic path we store paths
    in a list.  This allows for improved detection of mountpoins, free
    space, etc..

This patch

Simplify the Device object from a vector of paths to a single path.
Remove add_paths() and get_paths() methods.  Keep add_path() and
get_path() for now.

Bug 767842 - File system usage missing when tools report alternate block
             device names
This commit is contained in:
Mike Fleetwood 2016-06-02 07:49:53 +01:00 committed by Curtis Gedak
parent 7745abd767
commit 902afaa010
4 changed files with 7 additions and 52 deletions

View File

@ -33,9 +33,7 @@ public:
Device get_copy_without_partitions() const;
void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
void add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths = false ) ;
Glib::ustring get_path() const ;
std::vector<Glib::ustring> get_paths() const ;
void enable_partition_naming( int length ); // > 0 => enable partition naming support
bool partition_naming_supported() const;
int get_max_partition_name_length() const;
@ -59,11 +57,7 @@ public:
bool readonly ;
private:
void sort_paths_and_remove_duplicates() ;
static bool compare_paths( const Glib::ustring & A, const Glib::ustring & B ) ;
std::vector<Glib::ustring> paths ;
Glib::ustring path;
int max_partition_name_length; // > 0 => naming of partitions is supported on this device
};

View File

@ -27,7 +27,7 @@ Device::Device()
void Device::Reset()
{
paths .clear() ;
path.clear();
partitions .clear() ;
length = cylsize = 0 ;
heads = sectors = cylinders = 0 ;
@ -53,42 +53,19 @@ Device Device::get_copy_without_partitions() const
new_device.max_prims = this->max_prims;
new_device.highest_busy = this->highest_busy;
new_device.readonly = this->readonly;
new_device.paths = this->paths;
new_device.path = this->path;
new_device.max_partition_name_length = this->max_partition_name_length;
return new_device; // (3) Return by value.
}
void Device::add_path( const Glib::ustring & path, bool clear_paths )
{
if ( clear_paths )
paths .clear() ;
paths .push_back( path ) ;
sort_paths_and_remove_duplicates() ;
}
void Device::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() ;
this->path = path;
}
Glib::ustring Device::get_path() const
{
if ( paths .size() > 0 )
return paths .front() ;
return "" ;
}
std::vector<Glib::ustring> Device::get_paths() const
{
return paths ;
return path;
}
void Device::enable_partition_naming( int max_length )
@ -119,21 +96,6 @@ bool Device::operator!=( const Device & device ) const
return ! ( *this == device ) ;
}
void Device::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 ) ;
}
bool Device::compare_paths( const Glib::ustring & A, const Glib::ustring & B )
{
return A .length() < B .length() ;
}
Device::~Device()
{
}

View File

@ -278,7 +278,6 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
//device info..
temp_device .add_path( device_paths[ t ] ) ;
temp_device .add_paths( pp_info .get_alternate_paths( temp_device .get_path() ) ) ;
temp_device .model = lp_device ->model ;
temp_device .length = lp_device ->length ;

View File

@ -692,8 +692,8 @@ void Win_GParted::Fill_Label_Device_Info( bool clear )
device_info[ t++ ] ->set_text( devices[ current_device ] .model ) ;
device_info[ t++ ] ->set_text( devices[current_device].serial_number );
device_info[ t++ ] ->set_text( Utils::format_size( devices[ current_device ] .length, devices[ current_device ] .sector_size ) ) ;
device_info[ t++ ] ->set_text( Glib::build_path( "\n", devices[ current_device ] .get_paths() ) ) ;
device_info[ t++ ] ->set_text( devices[current_device].get_path() );
//detailed info
device_info[ t++ ] ->set_text( devices[ current_device ] .disktype ) ;
device_info[ t++ ] ->set_text( Utils::num_to_str( devices[ current_device ] .heads ) );