mirror of
https://gitlab.gnome.org/GNOME/gparted
synced 2024-08-27 03:30:17 +00:00
Improve initialization logic for FS_Info class
Ensure that fs_info_cache is populated in any first instantiation in a program, even for an instantiation such as: FS_Info A(false);
This commit is contained in:
parent
a05751ea95
commit
8d024d86df
|
@ -34,7 +34,10 @@ public:
|
|||
Glib::ustring get_uuid( const Glib::ustring & path ) ;
|
||||
private:
|
||||
void load_fs_info_cache() ;
|
||||
void set_commands_found() ;
|
||||
Glib::ustring get_device_entry( const Glib::ustring & path ) ;
|
||||
static bool fs_info_cache_initialized ;
|
||||
static bool blkid_found ;
|
||||
static Glib::ustring fs_info_cache ;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,18 +20,33 @@
|
|||
namespace GParted
|
||||
{
|
||||
|
||||
//initialize static data element
|
||||
//initialize static data elements
|
||||
bool FS_Info::fs_info_cache_initialized = false ;
|
||||
bool FS_Info::blkid_found = false ;
|
||||
Glib::ustring FS_Info::fs_info_cache = "";
|
||||
|
||||
FS_Info::FS_Info()
|
||||
{
|
||||
//Ensure that cache has been loaded at least once
|
||||
if ( fs_info_cache == "" )
|
||||
if ( ! fs_info_cache_initialized )
|
||||
{
|
||||
fs_info_cache_initialized = true ;
|
||||
set_commands_found() ;
|
||||
load_fs_info_cache() ;
|
||||
}
|
||||
}
|
||||
|
||||
FS_Info:: FS_Info( bool do_refresh )
|
||||
{
|
||||
//Ensure that cache has been loaded at least once
|
||||
if ( ! fs_info_cache_initialized )
|
||||
{
|
||||
fs_info_cache_initialized = true ;
|
||||
set_commands_found() ;
|
||||
if ( do_refresh == false )
|
||||
load_fs_info_cache() ;
|
||||
}
|
||||
|
||||
if ( do_refresh )
|
||||
load_fs_info_cache() ;
|
||||
}
|
||||
|
@ -43,7 +58,7 @@ FS_Info::~FS_Info()
|
|||
void FS_Info::load_fs_info_cache()
|
||||
{
|
||||
Glib::ustring output, error ;
|
||||
if ( ! Glib::find_program_in_path( "blkid" ) .empty() )
|
||||
if ( blkid_found )
|
||||
{
|
||||
if ( ! Utils::execute_command( "blkid -c /dev/null", output, error, true ) )
|
||||
fs_info_cache = output ;
|
||||
|
@ -52,6 +67,12 @@ void FS_Info::load_fs_info_cache()
|
|||
}
|
||||
}
|
||||
|
||||
void FS_Info::set_commands_found()
|
||||
{
|
||||
//Set status of commands found
|
||||
blkid_found = (! Glib::find_program_in_path( "blkid" ) .empty() ) ;
|
||||
}
|
||||
|
||||
Glib::ustring FS_Info::get_device_entry( const Glib::ustring & path )
|
||||
{
|
||||
//Retrieve the line containing the device path
|
||||
|
|
Loading…
Reference in a new issue