Ensure FS_Info (blkid) cache is populated before first use (#131)
Now we always want to run blkid naming all paths, ensure the FS_Info cache is explicitly loaded first. Report an error if not done so and remove the cache loading code from running blkid without naming all paths. Fewer code paths to consider and reason about. Closes #131 - GParted hangs when non-named device is hung
This commit is contained in:
parent
d86d9ae830
commit
52ed42de28
|
@ -46,7 +46,7 @@ public:
|
|||
static Glib::ustring get_path_by_label( const Glib::ustring & label );
|
||||
|
||||
private:
|
||||
static void initialize_if_required();
|
||||
static bool not_initialised_then_error();
|
||||
static void set_commands_found();
|
||||
static const FS_Entry & get_cache_entry_by_path( const Glib::ustring & path );
|
||||
static void load_fs_info_cache(const std::vector<Glib::ustring>& paths);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "BlockSpecial.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <glibmm/miscutils.h>
|
||||
#include <glibmm/shell.h>
|
||||
|
@ -61,7 +62,9 @@ void FS_Info::load_cache_for_paths(const std::vector<Glib::ustring>& paths)
|
|||
// Retrieve the file system type for the path
|
||||
Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
|
||||
{
|
||||
initialize_if_required();
|
||||
if (not_initialised_then_error())
|
||||
return "";
|
||||
|
||||
const FS_Entry & fs_entry = get_cache_entry_by_path( path );
|
||||
Glib::ustring fs_type = fs_entry.type;
|
||||
Glib::ustring fs_sec_type = fs_entry.sec_type;
|
||||
|
@ -93,7 +96,12 @@ Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
|
|||
// Retrieve the label and set found indicator for the path
|
||||
Glib::ustring FS_Info::get_label( const Glib::ustring & path, bool & found )
|
||||
{
|
||||
initialize_if_required();
|
||||
if (not_initialised_then_error())
|
||||
{
|
||||
found = false;
|
||||
return "";
|
||||
}
|
||||
|
||||
BlockSpecial bs = BlockSpecial( path );
|
||||
for ( unsigned int i = 0 ; i < fs_info_cache.size() ; i ++ )
|
||||
if ( bs == fs_info_cache[i].path )
|
||||
|
@ -119,7 +127,9 @@ Glib::ustring FS_Info::get_label( const Glib::ustring & path, bool & found )
|
|||
// Retrieve the uuid given for the path
|
||||
Glib::ustring FS_Info::get_uuid( const Glib::ustring & path )
|
||||
{
|
||||
initialize_if_required();
|
||||
if (not_initialised_then_error())
|
||||
return "";
|
||||
|
||||
const FS_Entry & fs_entry = get_cache_entry_by_path( path );
|
||||
return fs_entry.uuid;
|
||||
}
|
||||
|
@ -127,7 +137,9 @@ Glib::ustring FS_Info::get_uuid( const Glib::ustring & path )
|
|||
// Retrieve the path given the uuid
|
||||
Glib::ustring FS_Info::get_path_by_uuid( const Glib::ustring & uuid )
|
||||
{
|
||||
initialize_if_required();
|
||||
if (not_initialised_then_error())
|
||||
return "";
|
||||
|
||||
for ( unsigned int i = 0 ; i < fs_info_cache.size() ; i ++ )
|
||||
if ( uuid == fs_info_cache[i].uuid )
|
||||
return fs_info_cache[i].path.m_name;
|
||||
|
@ -138,7 +150,9 @@ Glib::ustring FS_Info::get_path_by_uuid( const Glib::ustring & uuid )
|
|||
// Retrieve the path given the label
|
||||
Glib::ustring FS_Info::get_path_by_label( const Glib::ustring & label )
|
||||
{
|
||||
initialize_if_required();
|
||||
if (not_initialised_then_error())
|
||||
return "";
|
||||
|
||||
update_fs_info_cache_all_labels();
|
||||
for ( unsigned int i = 0 ; i < fs_info_cache.size() ; i ++ )
|
||||
if ( label == fs_info_cache[i].label )
|
||||
|
@ -149,17 +163,14 @@ Glib::ustring FS_Info::get_path_by_label( const Glib::ustring & label )
|
|||
|
||||
// Private methods
|
||||
|
||||
void FS_Info::initialize_if_required()
|
||||
bool FS_Info::not_initialised_then_error()
|
||||
{
|
||||
if (! fs_info_cache_initialized)
|
||||
{
|
||||
set_commands_found();
|
||||
std::vector<Glib::ustring> empty;
|
||||
load_fs_info_cache(empty);
|
||||
fs_info_cache_initialized = true;
|
||||
}
|
||||
std::cerr << "GParted Bug: FS_Info (blkid) cache not loaded before use" << std::endl;
|
||||
return ! fs_info_cache_initialized;
|
||||
}
|
||||
|
||||
|
||||
void FS_Info::set_commands_found()
|
||||
{
|
||||
//Set status of commands found
|
||||
|
|
Loading…
Reference in New Issue