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:
Mike Fleetwood 2022-06-17 11:00:55 +01:00 committed by Curtis Gedak
parent 1424b7a5f4
commit 407e0ac6e3
1 changed files with 12 additions and 12 deletions

View File

@ -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 = "" ;