[gparted] Refactor fat16::read_label() into if fail return early pattern (!104)



commit 407e0ac6e3922306133b24359e997b637599f2b3
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jun 17 11:00:55 2022 +0100

    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

 src/fat16.cc | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/src/fat16.cc b/src/fat16.cc
index 5aeb0c95..530630c1 100644
--- a/src/fat16.cc
+++ b/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 )                                           )
-       {
-               partition.set_filesystem_label( Utils::trim( Utils::regexp_label( output, "Volume label is 
([^(]*)" ) ) );
-       }
-       else
+       exit_status = Utils::execute_command("mlabel -s :: -i " + Glib::shell_quote(partition.get_path()),
+                                            output, error, true);
+       if (exit_status != 0)
        {
-               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 = "" ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]