[gparted/psusi/refactor: 14/19] Refactor reiser4 to use execute_command_async
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 14/19] Refactor reiser4 to use execute_command_async
- Date: Tue, 20 Mar 2012 00:03:36 +0000 (UTC)
commit 146368623f05d95dcb454db077886e3cc6f0439f
Author: Phillip Susi <psusi ubuntu com>
Date: Sun Feb 19 23:52:32 2012 -0500
Refactor reiser4 to use execute_command_async
Instead of Filesystem::execute_command or Utils::execute_command, the
reiser4 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/reiser4.h | 17 ++++++
src/reiser4.cc | 155 +++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 139 insertions(+), 33 deletions(-)
---
diff --git a/include/reiser4.h b/include/reiser4.h
index 38c60f8..b78466a 100644
--- a/include/reiser4.h
+++ b/include/reiser4.h
@@ -30,20 +30,37 @@ class reiser4 : 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 );
};
} //GParted
diff --git a/src/reiser4.cc b/src/reiser4.cc
index 859b8f3..ed4a090 100644
--- a/src/reiser4.cc
+++ b/src/reiser4.cc
@@ -57,47 +57,77 @@ FS reiser4::get_filesystem_support()
return fs ;
}
-void reiser4::set_used_sectors( Partition & partition )
+void reiser4::set_used_sectors( Partition & partition )
{
- if ( ! Utils::execute_command( "debugfs.reiser4 " + partition .get_path(), output, error, true ) )
+ set_used_sectors( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void reiser4::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "debugfs.reiser4 " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiser4::set_used_sectors2 ),
+ &partition ) );
+}
+
+bool reiser4::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( "blksize" ) ;
+ index = output .find( "free blocks" );
if ( index >= output.length() ||
- sscanf( output.substr( index ) .c_str(), "blksize: %Ld", &S ) != 1 )
- S = -1 ;
-
+ sscanf( output.substr( index ).c_str(), "free blocks: %Ld", &N ) != 1 )
+ N = -1;
+ index = output.find( "blksize" );
+ if ( index >= output.length() ||
+ sscanf( output.substr( index ).c_str(), "blksize: %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) ) ) );
}
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 reiser4::read_label( Partition & partition )
{
- if ( ! Utils::execute_command( "vol_id " + partition .get_path(), output, error, true ) )
+ read_label( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void reiser4::read_label( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "vol_id " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiser4::read_label2 ),
+ &partition ) );
+}
+
+bool reiser4::read_label2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .label = Utils::regexp_label( output, "ID_FS_LABEL=([^\n]*)" ) ;
+ partition->label = Utils::regexp_label( output, "ID_FS_LABEL=([^\n]*)" );
}
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 reiser4::write_label( const Partition & partition, OperationDetail & operationdetail )
@@ -105,20 +135,40 @@ bool reiser4::write_label( const Partition & partition, OperationDetail & operat
return true ;
}
+void reiser4::write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
void reiser4::read_uuid( Partition & partition )
{
- if ( ! Utils::execute_command( "fsck.reiser4 --check --yes " + partition .get_path(), output, error, true ) )
+ read_uuid( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void reiser4::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "fsck.reiser4 --check --yes " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiser4::read_uuid2 ),
+ &partition ) );
+}
+
+bool reiser4::read_uuid2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .uuid = Utils::regexp_label( error, "uuid:[[:blank:]]*([^[:space:]]*)" ) ;
+ partition->uuid = Utils::regexp_label( error, "uuid:[[:blank:]]*([^[:space:]]*)" );
}
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 reiser4::write_uuid( const Partition & partition, OperationDetail & operationdetail )
@@ -126,9 +176,23 @@ bool reiser4::write_uuid( const Partition & partition, OperationDetail & operati
return true ;
}
+void reiser4::write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool reiser4::create( const Partition & new_partition, OperationDetail & operationdetail )
{
- return ! execute_command( "mkfs.reiser4 --yes --label \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ;
+ create( new_partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiser4::create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "mkfs.reiser4 --yes --label \"" + new_partition .label + "\" " + new_partition .get_path(),
+ operationdetail,
+ set_success );
}
bool reiser4::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
@@ -136,6 +200,11 @@ bool reiser4::resize( const Partition & partition_new, OperationDetail & operati
return true ;
}
+void reiser4::resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot )
+{
+}
+
bool reiser4::move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
@@ -144,6 +213,11 @@ bool reiser4::move( const Partition & partition_new
return true ;
}
+void reiser4::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool reiser4::copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
@@ -151,9 +225,24 @@ bool reiser4::copy( const Glib::ustring & src_part_path,
return true ;
}
+void reiser4::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool reiser4::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "fsck.reiser4 --yes --fix --quiet " + partition .get_path(), operationdetail ) ;
+ check_repair( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiser4::check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "fsck.reiser4 --yes --fix --quiet " + partition.get_path(),
+ operationdetail,
+ set_success );
}
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]