Refactor ntfs resize code (#790842)

Refactor nested if-then-else into a sequence of if fail return early.
Makes the code simpler to understand and converts separate
OperationDetail::set_status() calls for success or error into a single
call using ternary conditional matching how it is or was done everywhere
else.  This is also ready for status and error capture refactoring.

Bug 790842 - Report libparted messages into operation details at the
             point at which they occur
This commit is contained in:
Mike Fleetwood 2017-11-25 16:16:20 +00:00 committed by Curtis Gedak
parent 76088a39de
commit bf1e87ecf3
1 changed files with 13 additions and 27 deletions

View File

@ -215,7 +215,7 @@ bool ntfs::create( const Partition & new_partition, OperationDetail & operationd
bool ntfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
bool return_value = false ;
bool success;
Glib::ustring size = "" ;
if ( ! fill_partition )
{
@ -226,33 +226,19 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
//simulation..
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 );
if ( ! success )
return false;
if ( ! 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( STATUS_SUCCES ) ;
//real resize
operationdetail .add_child( OperationDetail( _("real resize") ) ) ;
if ( ! 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( STATUS_SUCCES ) ;
return_value = true ;
}
else
{
operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
}
}
else
{
operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
}
return return_value ;
// Real resize
operationdetail.add_child( OperationDetail( _("real resize") ) );
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 );
return success;
}
bool ntfs::copy( const Partition & src_part,