Refactor fat16::read_label() into if fail return early pattern (!104)
Follows the "Return Early" design pattern making the code easier to understand without having to remember cases for elses or cascading ifs. Refactor before the following commit's fix so that capture of output on failure can be confirmed as still working. Closes !104 - Add Alpine Linux CI jobs and resolve label and UUID issues with FAT16/32
This commit is contained in:
parent
1424b7a5f4
commit
407e0ac6e3
24
src/fat16.cc
24
src/fat16.cc
|
@ -190,23 +190,23 @@ void fat16::set_used_sectors( Partition & partition )
|
|||
}
|
||||
|
||||
|
||||
void fat16::read_label( Partition & partition )
|
||||
void fat16::read_label(Partition& partition)
|
||||
{
|
||||
if ( ! Utils::execute_command( "mlabel -s :: -i " + Glib::shell_quote( partition.get_path() ),
|
||||
output, error, true ) )
|
||||
exit_status = Utils::execute_command("mlabel -s :: -i " + Glib::shell_quote(partition.get_path()),
|
||||
output, error, true);
|
||||
if (exit_status != 0)
|
||||
{
|
||||
partition.set_filesystem_label( Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! output .empty() )
|
||||
partition.push_back_message( output );
|
||||
|
||||
if ( ! error .empty() )
|
||||
partition.push_back_message( error );
|
||||
if (! output.empty())
|
||||
partition.push_back_message(output);
|
||||
if (! error.empty())
|
||||
partition.push_back_message(error);
|
||||
return;
|
||||
}
|
||||
|
||||
partition.set_filesystem_label(Utils::trim(Utils::regexp_label(output, "Volume label is ([^(]*)")));
|
||||
}
|
||||
|
||||
|
||||
bool fat16::write_label( const Partition & partition, OperationDetail & operationdetail )
|
||||
{
|
||||
Glib::ustring cmd = "" ;
|
||||
|
|
Loading…
Reference in New Issue