[gparted] Transition other code to callback error collection (#790842)



commit 2040aabd22b8ef7da46a9596bfece0b903b17e7f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Nov 25 16:31:47 2017 +0000

    Transition other code to callback error collection (#790842)
    
    Transition all remaining code, DMRaid and file system code, to use the
    new method of reporting success of a step and automatic error
    collection.  None of this code calls libparted so can't generate any
    libparted exceptions.  This is just for consistency so all code follows
    the same pattern using set_success_and_capture_errors().
    
    Bug 790842 - Report libparted messages into operation details at the
                 point at which they occur

 src/DMRaid.cc     |   12 ++++--------
 src/FileSystem.cc |   15 +++++----------
 src/ntfs.cc       |    4 ++--
 3 files changed, 11 insertions(+), 20 deletions(-)
---
diff --git a/src/DMRaid.cc b/src/DMRaid.cc
index 59bef34..9276bef 100644
--- a/src/DMRaid.cc
+++ b/src/DMRaid.cc
@@ -333,8 +333,7 @@ bool DMRaid::create_dev_map_entries( const Partition & partition, OperationDetai
        if ( execute_command( "dmraid -ay -P \"\" -v", operationdetail.get_last_child() ) )
                exit_status = false;  // command failed
 
-       operationdetail .get_last_child() .set_status( exit_status ? STATUS_SUCCES : STATUS_ERROR ) ;
-
+       operationdetail.get_last_child().set_success_and_capture_errors( exit_status );
        return exit_status ;
 }
 
@@ -422,8 +421,7 @@ bool DMRaid::delete_affected_dev_map_entries( const Partition & partition, Opera
                        exit_status = false ;   //command failed
        }
 
-       operationdetail .get_last_child() .set_status( exit_status ? STATUS_SUCCES : STATUS_ERROR ) ;
-
+       operationdetail.get_last_child().set_success_and_capture_errors( exit_status );
        return exit_status ;
 }
 
@@ -446,8 +444,7 @@ bool DMRaid::delete_dev_map_entry( const Partition & partition, OperationDetail
                        exit_status = false ;   //command failed
        }
 
-       operationdetail .get_last_child() .set_status( exit_status ? STATUS_SUCCES : STATUS_ERROR ) ;
-
+       operationdetail.get_last_child().set_success_and_capture_errors( exit_status );
        return exit_status ;
 }
 
@@ -492,8 +489,7 @@ bool DMRaid::update_dev_map_entry( const Partition & partition, OperationDetail
        if( ! create_dev_map_entries( partition , operationdetail .get_last_child() ) )
                exit_status = false ;   //command failed
 
-       operationdetail .get_last_child() .set_status( exit_status ? STATUS_SUCCES : STATUS_ERROR ) ;
-
+       operationdetail.get_last_child().set_success_and_capture_errors( exit_status );
        return exit_status ;
 }
 
diff --git a/src/FileSystem.cc b/src/FileSystem.cc
index c89ac02..dfdc356 100644
--- a/src/FileSystem.cc
+++ b/src/FileSystem.cc
@@ -168,12 +168,7 @@ int FileSystem::execute_command_internal( const Glib::ustring & command, Operati
        Gtk::Main::run();
 
        if ( flags & EXEC_CHECK_STATUS )
-       {
-               if ( !exit_status )
-                       cmd_operationdetail.set_status( STATUS_SUCCES );
-               else
-                       cmd_operationdetail.set_status( STATUS_ERROR );
-       }
+               cmd_operationdetail.set_success_and_capture_errors( exit_status == 0 );
        close( out );
        close( err );
        if ( timed_conn.connected() )
@@ -184,7 +179,7 @@ int FileSystem::execute_command_internal( const Glib::ustring & command, Operati
 
 void FileSystem::set_status( OperationDetail & operationdetail, bool success )
 {
-       operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+       operationdetail.get_last_child().set_success_and_capture_errors( success );
 }
 
 void FileSystem::execute_command_eof()
@@ -215,7 +210,7 @@ Glib::ustring FileSystem::mk_temp_dir( const Glib::ustring & infix, OperationDet
        if ( NULL == dir_name )
        {
                int e = errno ;
-               operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
+               operationdetail.get_last_child().set_success_and_capture_errors( false );
                operationdetail .get_last_child() .add_child( OperationDetail(
                                String::ucompose( "mkdtemp(%1): %2", dir_buf, Glib::strerror( e ) ), 
STATUS_NONE ) ) ;
                dir_name = "" ;
@@ -225,7 +220,7 @@ Glib::ustring FileSystem::mk_temp_dir( const Glib::ustring & infix, OperationDet
                //Update command with actually created temporary directory
                operationdetail .get_last_child() .set_description(
                                Glib::ustring( "mkdir -v " ) + dir_name, FONT_BOLD_ITALIC ) ;
-               operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
+               operationdetail.get_last_child().set_success_and_capture_errors( true );
                operationdetail .get_last_child() .add_child( OperationDetail(
                                /*TO TRANSLATORS: looks like   Created directory /tmp/gparted-CEzvSp */
                                String::ucompose( _("Created directory %1"), dir_name ), STATUS_NONE ) ) ;
@@ -251,7 +246,7 @@ void FileSystem::rm_temp_dir( const Glib::ustring dir_name, OperationDetail & op
        }
        else
        {
-               operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
+               operationdetail.get_last_child().set_success_and_capture_errors( true );
                operationdetail .get_last_child() .add_child( OperationDetail(
                                /*TO TRANSLATORS: looks like   Removed directory /tmp/gparted-CEzvSp */
                                String::ucompose( _("Removed directory %1"), dir_name ), STATUS_NONE ) ) ;
diff --git a/src/ntfs.cc b/src/ntfs.cc
index e418376..547aec9 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -228,7 +228,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
        operationdetail .add_child( OperationDetail( _("run simulation") ) ) ;
        success = ! execute_command( cmd + " --no-action " + Glib::shell_quote( partition_new.get_path() ),
                                     operationdetail.get_last_child(), EXEC_CHECK_STATUS );
-       operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+       operationdetail.get_last_child().set_success_and_capture_errors( success );
        if ( ! success )
                return false;
 
@@ -237,7 +237,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
        success = ! execute_command( cmd + " " + Glib::shell_quote( partition_new.get_path() ),
                                     operationdetail.get_last_child(), EXEC_CHECK_STATUS|EXEC_PROGRESS_STDOUT,
                                     static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::resize_progress ) 
) );
-       operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+       operationdetail.get_last_child().set_success_and_capture_errors( success );
        return success;
 }
 


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