[gparted/psusi/refactor: 6/19] Refactor ext3 to use execute_command_async
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 6/19] Refactor ext3 to use execute_command_async
- Date: Tue, 20 Mar 2012 00:02:56 +0000 (UTC)
commit 8315538340daed00dc7e1e15d2ca6897ee3c19c2
Author: Phillip Susi <psusi ubuntu com>
Date: Sun Feb 12 21:14:39 2012 -0500
Refactor ext3 to use execute_command_async
Instead of Filesystem::execute_command or Utils::execute_command, the ext3
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/ext3.h | 23 +++++++
src/ext3.cc | 196 +++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 181 insertions(+), 38 deletions(-)
---
diff --git a/include/ext3.h b/include/ext3.h
index 3e349f7..08e51ce 100644
--- a/include/ext3.h
+++ b/include/ext3.h
@@ -30,20 +30,43 @@ class ext3 : public FileSystem
public:
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 );
+private:
+ bool set_used_sectors2( double progress, Partition *partition );
+ bool read_label2( double progress, Partition *partition );
+ bool read_uuid2( double progress, Partition *partition );
+ bool write_uuid2( double progress );
+ bool check_repair2( double progress );
};
diff --git a/src/ext3.cc b/src/ext3.cc
index 9a438da..5746e6d 100644
--- a/src/ext3.cc
+++ b/src/ext3.cc
@@ -63,115 +63,235 @@ FS ext3::get_filesystem_support()
return fs ;
}
-void ext3::set_used_sectors( Partition & partition )
+void ext3::set_used_sectors( Partition & partition )
{
- if ( ! Utils::execute_command( "dumpe2fs -h " + partition .get_path(), output, error, true ) )
+ set_used_sectors( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void ext3::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "dumpe2fs -h " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &ext3::set_used_sectors2 ),
+ &partition ) );
+}
+
+bool ext3::set_used_sectors2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
index = output .find( "Free blocks:" ) ;
if ( index >= output .length() ||
sscanf( output.substr( index ) .c_str(), "Free blocks: %Ld", &N ) != 1 )
N = -1 ;
-
+
index = output .find( "Block size:" ) ;
if ( index >= output.length() ||
sscanf( output.substr( index ) .c_str(), "Block size: %Ld", &S ) != 1 )
S = -1 ;
if ( N > -1 && S > -1 )
- partition .Set_Unused( Utils::round( N * ( S / double(partition .sector_size) ) ) ) ;
+ partition->Set_Unused( Utils::round( N * ( S / double(partition->sector_size) ) ) );
+ success = true;
}
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 );
+ success = false;
}
+ return slot( 1.0 );
}
void ext3::read_label( Partition & partition )
{
- if ( ! Utils::execute_command( "e2label " + partition .get_path(), output, error, true ) )
+ read_label( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void ext3::read_label( Partition & partition, sigc::slot<bool, double> slot )
+{
+ execute_command( "e2label " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &ext3::read_label2 ),
+ &partition ) );
+}
+
+bool ext3::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 );
+ success = true;
}
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 );
+ success = false;
}
+ return slot( 1.0 );
}
bool ext3::write_label( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "e2label " + partition .get_path() + " \"" + partition .label + "\"", operationdetail ) ;
+ write_label( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ext3::write_label( const Partition & partition, OperationDetail & operationdetail,
+ sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "e2label " + partition .get_path() + " \"" + partition .label + "\"",
+ operationdetail,
+ set_success );
}
void ext3::read_uuid( Partition & partition )
{
- if ( ! Utils::execute_command( "tune2fs -l " + partition .get_path(), output, error, true ) )
+ read_uuid( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void ext3::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+ execute_command( "tune2fs -l " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &ext3::read_uuid2 ),
+ &partition ) );
+}
+
+bool ext3::read_uuid2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*([^[:space:]]*)" ) ;
- if (partition .uuid == "<none>")
- partition .uuid .clear() ;
+ partition->uuid = Utils::regexp_label( output, "^Filesystem UUID:[[:blank:]]*([^[:space:]]*)" );
+ if (partition->uuid == "<none>")
+ partition->uuid.clear();
}
else
{
- if ( ! output .empty() )
- partition .messages .push_back( output ) ;
+ if ( !output.empty() )
+ partition->messages.push_back( output );
- if ( ! error .empty() )
- partition .messages .push_back( error ) ;
+ if ( !error.empty() )
+ partition->messages.push_back( error );
}
+ return slot( 1.0 );
}
bool ext3::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "tune2fs -U random " + partition .get_path(), operationdetail ) ;
+ write_uuid( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ext3::write_uuid( const Partition & partition, OperationDetail & operationdetail,
+ sigc::slot<bool, double> slot )
+{
+ execute_command( "tune2fs -U random " + partition .get_path(),
+ operationdetail,
+ set_success );
}
bool ext3::create( const Partition & new_partition, OperationDetail & operationdetail )
{
- return ! execute_command( "mkfs.ext3 -L \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ;
+ create( new_partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ext3::create( const Partition & new_partition, OperationDetail & operationdetail,
+ sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "mkfs.ext3 -L \"" + new_partition .label + "\" " + new_partition .get_path(),
+ operationdetail,
+ set_success );
}
bool ext3::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
+ resize( partition_new, operationdetail, fill_partition, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ext3::resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
Glib::ustring str_temp = "resize2fs " + partition_new .get_path() ;
-
+
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) -1 ) + "K" ;
- return ! execute_command( str_temp, operationdetail ) ;
+ execute_command( str_temp, operationdetail, set_success );
+}
+
+bool ext3::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail )
+{
+ return false;
}
-bool ext3::move( const Partition & partition_new
- , const Partition & partition_old
- , OperationDetail & operationdetail
- )
+void ext3::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
{
- return true ;
+ success = false;
+ slot( 1.0 );
}
-bool ext3::copy( const Glib::ustring & src_part_path,
- const Glib::ustring & dest_part_path,
+bool ext3::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
{
return true ;
}
+void ext3::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ success = false;
+ slot( 1.0 );
+}
+
bool ext3::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
- exit_status = execute_command( "e2fsck -f -y -v " + partition .get_path(), operationdetail ) ;
+ check_repair( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void ext3::check_repair( const Partition & partition, OperationDetail & operationdetail,
+ sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "e2fsck -f -y -v " + partition .get_path(),
+ operationdetail,
+ sigc::mem_fun( *this, &ext3::check_repair2 ) );
+}
+bool ext3::check_repair2( double progress )
+{
+ if ( progress != 1.0 )
+ return false;
//exitstatus 256 isn't documented, but it's returned when the 'FILE SYSTEM IS MODIFIED'
//this is quite normal (especially after a copy) so we let the function return true...
- return ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 ) ;
+ success = ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 );
+ return slot( 1.0 );
}
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]