Simplify DMRaid::get_udev_dm_name()
Use if false return early pattern for the udevadm command found check. Don't bother to check the exit status from running the udevadm command or whether the output string contains anything before trying to parse it for the serial number using Utils::regexp_label(). If the output string is empty because either the udevadm command failed or the device has no serial number then Utils::regexp_label() will assign the empty string to serial_number; exactly what is wanted for these failure cases. This makes the code simpler and easier to understand and still produces the desired results in the failure cases.
This commit is contained in:
parent
78c1986da5
commit
ad97634246
|
@ -273,26 +273,24 @@ int DMRaid::get_partition_number( const Glib::ustring & partition_name )
|
||||||
return std::atoi( Utils::regexp_label( partition_name, dmraid_name + "p?([0-9]+)" ) .c_str() ) ;
|
return std::atoi( Utils::regexp_label( partition_name, dmraid_name + "p?([0-9]+)" ) .c_str() ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Glib::ustring DMRaid::get_udev_dm_name( const Glib::ustring & dev_path )
|
Glib::ustring DMRaid::get_udev_dm_name( const Glib::ustring & dev_path )
|
||||||
{
|
{
|
||||||
|
Glib::ustring dm_name;
|
||||||
|
if (! udevadm_found)
|
||||||
|
return dm_name;
|
||||||
|
|
||||||
//Retrieve DM_NAME of device using udev information
|
//Retrieve DM_NAME of device using udev information
|
||||||
Glib::ustring output;
|
Glib::ustring output;
|
||||||
Glib::ustring error;
|
Glib::ustring error;
|
||||||
Glib::ustring dm_name;
|
Utils::execute_command("udevadm info --query=all --name=" + Glib::shell_quote(dev_path),
|
||||||
|
output, error, true);
|
||||||
if (udevadm_found)
|
dm_name = Utils::regexp_label(output, "^E: DM_NAME=([^\n]*)$");
|
||||||
Utils::execute_command( "udevadm info --query=all --name=" + Glib::shell_quote( dev_path ),
|
|
||||||
output, error, true );
|
|
||||||
|
|
||||||
if ( ! output .empty() )
|
|
||||||
{
|
|
||||||
Glib::ustring regexp = "^E: DM_NAME=([^\n]*)$" ;
|
|
||||||
dm_name = Utils::regexp_label( output, regexp ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dm_name ;
|
return dm_name ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Glib::ustring DMRaid::make_path_dmraid_compatible( Glib::ustring partition_path )
|
Glib::ustring DMRaid::make_path_dmraid_compatible( Glib::ustring partition_path )
|
||||||
{
|
{
|
||||||
//The purpose of this method is to ensure that the partition name matches
|
//The purpose of this method is to ensure that the partition name matches
|
||||||
|
|
Loading…
Reference in New Issue