mirror of
https://gitlab.gnome.org/GNOME/gparted
synced 2024-08-27 03:30:17 +00:00
Update FS_Info cache with Unicode safe labels read from blkid (#786502)
Move the code which reads the Unicode label from FS_Info::get_label() into new function run_blkid_update_cache_one_label() which also replaces the non-reversibly encoded copy loaded during the initial cache load. This is mainly a bit of code refactoring ready for the following change. It deliberately keeps the initial loaded labels so that reading /etc/fstab and decoding LABEL=<label> to block special device names via FS_Info::get_path_by_label() continues to works, at least for ASCII only labels. Bug 786502 - Support reading Unicode labels when file system specific tools aren't available
This commit is contained in:
parent
1c984ae06d
commit
b022c1e3a9
|
@ -52,6 +52,7 @@ private:
|
|||
static void load_fs_info_cache();
|
||||
static void load_fs_info_cache_extra_for_path( const Glib::ustring & path );
|
||||
static bool run_blkid_load_cache( const Glib::ustring & path = "" );
|
||||
static bool run_blkid_update_cache_one_label( FS_Entry & fs_entry );
|
||||
|
||||
static bool fs_info_cache_initialized ;
|
||||
static bool blkid_found ;
|
||||
|
|
|
@ -89,26 +89,26 @@ Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
|
|||
Glib::ustring FS_Info::get_label( const Glib::ustring & path, bool & found )
|
||||
{
|
||||
initialize_if_required();
|
||||
if ( ! blkid_found )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( fs_info_cache[i].type == "" )
|
||||
{
|
||||
// This is a blank cache entry for a whole disk device
|
||||
// containing a partition table, so no label (as created
|
||||
// by load_fs_info_cache_extra_for_path()).
|
||||
found = false;
|
||||
return "";
|
||||
}
|
||||
|
||||
// (#786502) Run a separate blkid execution for a single partition to get the
|
||||
// label without blkid's default non-reversible encoding.
|
||||
Glib::ustring output;
|
||||
Glib::ustring error;
|
||||
found = ! Utils::execute_command( "blkid -o value -s LABEL " + path, output, error, true );
|
||||
size_t len = output.length();
|
||||
if ( len > 0 && output[len-1] == '\n' )
|
||||
{
|
||||
// Output is either the label with a terminating new line or zero bytes
|
||||
// when the file system has no label. Strip optional trailing new line
|
||||
// from blkid output.
|
||||
output.resize( len-1 );
|
||||
}
|
||||
return output;
|
||||
// Run blkid to get the label for this one partition, update the
|
||||
// cache and return the found label.
|
||||
found = run_blkid_update_cache_one_label( fs_info_cache[i] );
|
||||
return fs_info_cache[i].label;
|
||||
}
|
||||
found = false;
|
||||
return "";
|
||||
}
|
||||
|
||||
// Retrieve the uuid given for the path
|
||||
|
@ -269,4 +269,32 @@ bool FS_Info::run_blkid_load_cache( const Glib::ustring & path )
|
|||
return loaded_entries;
|
||||
}
|
||||
|
||||
bool FS_Info::run_blkid_update_cache_one_label( FS_Entry & fs_entry )
|
||||
{
|
||||
if ( ! blkid_found )
|
||||
return false;
|
||||
|
||||
// (#786502) Run a separate blkid execution for a single partition to get the
|
||||
// label without blkid's default non-reversible encoding.
|
||||
Glib::ustring output;
|
||||
Glib::ustring error;
|
||||
bool success = ! Utils::execute_command( "blkid -o value -s LABEL " + fs_entry.path.m_name,
|
||||
output, error, true );
|
||||
if ( ! success )
|
||||
return false;
|
||||
|
||||
size_t len = output.length();
|
||||
if ( len > 0 && output[len-1] == '\n' )
|
||||
{
|
||||
// Output is either the label with a terminating new line or zero bytes
|
||||
// when the file system has no label. Strip optional trailing new line
|
||||
// from blkid output.
|
||||
output.resize( len-1 );
|
||||
}
|
||||
// Update cache entry with the read label.
|
||||
fs_entry.have_label = true;
|
||||
fs_entry.label = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
}//GParted
|
||||
|
|
Loading…
Reference in a new issue