[gparted] Refactor ntfs resize code (#790842)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Refactor ntfs resize code (#790842)
- Date: Mon, 27 Nov 2017 17:42:39 +0000 (UTC)
commit bf1e87ecf31843d38fae416fdf66de3511b00f92
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sat Nov 25 16:16:20 2017 +0000
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
src/ntfs.cc | 42 ++++++++++++++----------------------------
1 files changed, 14 insertions(+), 28 deletions(-)
---
diff --git a/src/ntfs.cc b/src/ntfs.cc
index 7f161d6..e418376 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -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") ) ) ;
-
- 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 ;
+ 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;
+
+ // 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]