[gparted/psusi/refactor: 11/19] Refactor ntfs to use execute_command_async
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 11/19] Refactor ntfs to use execute_command_async
- Date: Tue, 20 Mar 2012 00:03:21 +0000 (UTC)
commit 42a231b1c54d0dd8bf1bfc4a1be6fb77e3273d99
Author: Phillip Susi <psusi ubuntu com>
Date: Fri Feb 17 22:58:28 2012 -0500
Refactor ntfs to use execute_command_async
Instead of Filesystem::execute_command or Utils::execute_command, the ntfs
methods now use Filesystem::execute_command_async, and block the calling
thread on a mutex until the job completes. Methods that invoked multiple
external utilities have been split into multiple functions that are
invoked as the callback when the previous command has completed.
include/ntfs.h | 20 +++++-
src/ntfs.cc | 221 ++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 186 insertions(+), 55 deletions(-)
---
diff --git a/include/ntfs.h b/include/ntfs.h
index 6101c8b..42d5f79 100644
--- a/include/ntfs.h
+++ b/include/ntfs.h
@@ -31,22 +31,40 @@ public:
const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
+ void set_used_sectors( Partition & partition, sigc::slot<bool, double> slot );
void read_label( Partition & partition ) ;
+ void read_label( Partition & partition, sigc::slot<bool, double> slot );
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
+ void write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
void read_uuid( Partition & partition ) ;
+ void read_uuid( Partition & partition, sigc::slot<bool, double> slot );
bool write_uuid( const Partition & partition, OperationDetail & operationdetail ) ;
+ void write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
+ void create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
+ void resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot );
bool move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
) ;
+ void move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
+ void copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
-
+ void check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
static const Glib::ustring Change_UUID_Warning [] ;
+private:
+ bool set_used_sectors2( double progress, Partition *partition );
+ bool read_label2( double progress, Partition *partition );
+ Glib::ustring str_temp;
+ bool resize2( double progress, OperationDetail *operationdetail );
+ bool resize3( double progress, OperationDetail *operationdetail );
};
} //GParted
diff --git a/src/ntfs.cc b/src/ntfs.cc
index 429dfbe..9941679 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -106,107 +106,194 @@ FS ntfs::get_filesystem_support()
return fs ;
}
-void ntfs::set_used_sectors( Partition & partition )
+void ntfs::set_used_sectors( Partition & partition )
{
- if ( ! Utils::execute_command(
- "ntfsresize --info --force --no-progress-bar " + partition .get_path(), output, error, true ) )
- {
- index = output .find( "resize at" ) ;
- if ( index >= output .length() ||
- sscanf( output .substr( index ) .c_str(), "resize at %Ld", &N ) != 1 )
- N = -1 ;
+ set_used_sectors( partition, unlock_mutex );
+ mutex.lock();
+}
+void ntfs::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "ntfsresize --info --force --no-progress-bar " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &ntfs::set_used_sectors2 ),
+ &partition ) );
+}
+
+bool ntfs::set_used_sectors2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
+ {
+ index = output.find( "resize at" );
+ if ( index >= output.length() ||
+ sscanf( output.substr( index ).c_str(), "resize at %Ld", &N ) != 1 )
+ N = -1;
if ( N > -1 )
- partition .set_used( Utils::round( N / double(partition .sector_size) ) ) ;
+ partition->set_used( Utils::round( N / double(partition->sector_size) ) );
}
else
{
- if ( ! output .empty() )
- partition .messages .push_back( output ) ;
-
- if ( ! error .empty() )
- partition .messages .push_back( error ) ;
+ if ( !output.empty() )
+ partition->messages.push_back( output );
+ if ( !error.empty() )
+ partition->messages.push_back( error );
}
+ return slot( 1.0 );
}
void ntfs::read_label( Partition & partition )
{
- if ( ! Utils::execute_command( "ntfslabel --force " + partition .get_path(), output, error, false ) )
+ read_label( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void ntfs::read_label( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "ntfslabel --force " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &ntfs::read_label2 ),
+ &partition ) );
+}
+
+bool ntfs::read_label2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .label = Utils::trim( output ) ;
+ partition->label = Utils::trim( output );
}
else
{
- if ( ! output .empty() )
- partition .messages .push_back( output ) ;
-
- if ( ! error .empty() )
- partition .messages .push_back( error ) ;
+ if ( !output.empty() )
+ partition->messages.push_back( output );
+ if ( !error.empty() )
+ partition->messages.push_back( error );
}
+ return slot( 1.0 );
}
bool ntfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "ntfslabel --force " + partition .get_path() + " \"" + partition .label + "\"", operationdetail ) ;
+ write_label( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "ntfslabel --force " + partition.get_path() + " \"" + partition.label + "\"",
+ operationdetail,
+ set_success );
}
void ntfs::read_uuid( Partition & partition )
{
}
+void ntfs::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+}
+
bool ntfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
+ write_uuid( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
if ( partition .uuid == UUID_RANDOM_NTFS_HALF )
- return ! execute_command( "ntfslabel --new-half-serial " + partition .get_path(), operationdetail ) ;
+ execute_command( "ntfslabel --new-half-serial " + partition .get_path(),
+ operationdetail,
+ set_success );
else
- return ! execute_command( "ntfslabel --new-serial " + partition .get_path(), operationdetail ) ;
-
- return true ;
+ execute_command( "ntfslabel --new-serial " + partition .get_path(),
+ operationdetail,
+ set_success );
}
bool ntfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
- return ! execute_command( "mkntfs -Q -v -L \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ;
+ create( new_partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ execute_command( "mkntfs -Q -v -L \"" + new_partition.label + "\" " + new_partition.get_path(),
+ operationdetail,
+ set_success );
}
bool ntfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
- bool return_value = false ;
- Glib::ustring str_temp = "ntfsresize -P --force --force " + partition_new .get_path() ;
-
- if ( ! fill_partition )
+ resize( partition_new, operationdetail, fill_partition, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ success = false;
+ str_temp = "ntfsresize -P --force --force " + partition_new .get_path();
+
+ if ( !fill_partition )
{
- str_temp += " -s " ;
+ str_temp += " -s ";
str_temp += Utils::num_to_str( Utils::round( Utils::sector_to_unit(
- partition_new .get_sector_length(), partition_new .sector_size, UNIT_BYTE ) ) -1 ) ;
+ partition_new.get_sector_length(), partition_new.sector_size, UNIT_BYTE ) ) -1 );
}
-
+
//simulation..
- operationdetail .add_child( OperationDetail( _("run simulation") ) ) ;
+ operationdetail.add_child( OperationDetail( _("run simulation") ) );
+ execute_command( str_temp + " --no-action", operationdetail.get_last_child(),
+ sigc::bind( sigc::mem_fun( *this, &ntfs::resize2 ),
+ &operationdetail ) );
+}
- if ( ! execute_command( str_temp + " --no-action", operationdetail .get_last_child() ) )
+bool ntfs::resize2( double progress, OperationDetail *operationdetail )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
+ operationdetail->get_last_child().set_status( STATUS_SUCCES );
//real resize
- operationdetail .add_child( OperationDetail( _("real resize") ) ) ;
-
- if ( ! execute_command( str_temp, operationdetail .get_last_child() ) )
- {
- operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
- return_value = true ;
- }
- else
- {
- operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
- }
+ operationdetail->add_child( OperationDetail( _("real resize") ) );
+ execute_command( str_temp, operationdetail->get_last_child(),
+ sigc::bind( sigc::mem_fun( *this, &ntfs::resize3 ),
+ operationdetail ) );
+ } else {
+ success = false;
+ operationdetail->get_last_child().set_status( STATUS_ERROR );
+ return slot( 1.0 );
}
- else
+ return false;
+}
+
+bool ntfs::resize3( double progress, OperationDetail *operationdetail )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
+ operationdetail->get_last_child().set_status( STATUS_SUCCES );
+ success = true;
+ } else {
+ operationdetail->get_last_child().set_status( STATUS_ERROR );
+ success = false;
}
-
- return return_value ;
+ return slot( 1.0 );
}
bool ntfs::move( const Partition & partition_new
@@ -217,16 +304,42 @@ bool ntfs::move( const Partition & partition_new
return true ;
}
+void ntfs::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool ntfs::copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
{
- return ! execute_command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path, operationdetail ) ;
+ copy( src_part_path, dest_part_path, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path,
+ operationdetail,
+ set_success );
}
bool ntfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "ntfsresize -P -i -f -v " + partition .get_path(), operationdetail ) ;
+ check_repair( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ntfs::check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "ntfsresize -P -i -f -v " + partition.get_path(),
+ operationdetail,
+ set_success );
}
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]