[gparted/psusi/refactor: 13/19] Refactor reiserfs to use execute_command_async
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 13/19] Refactor reiserfs to use execute_command_async
- Date: Tue, 20 Mar 2012 00:03:31 +0000 (UTC)
commit c8badeb42990e87e4f7554eada56b9797bbe659f
Author: Phillip Susi <psusi ubuntu com>
Date: Sun Feb 19 22:10:30 2012 -0500
Refactor reiserfs to use execute_command_async
Instead of Filesystem::execute_command or Utils::execute_command, the
reiserfs 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/reiserfs.h | 19 +++++
src/reiserfs.cc | 208 ++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 181 insertions(+), 46 deletions(-)
---
diff --git a/include/reiserfs.h b/include/reiserfs.h
index 74a24cb..bc3dff6 100644
--- a/include/reiserfs.h
+++ b/include/reiserfs.h
@@ -30,20 +30,39 @@ class reiserfs : 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 resize2( double progress );
+ bool check_repair2( double progress );
};
} //GParted
diff --git a/src/reiserfs.cc b/src/reiserfs.cc
index fc7a564..9719bb0 100644
--- a/src/reiserfs.cc
+++ b/src/reiserfs.cc
@@ -67,95 +67,185 @@ FS reiserfs::get_filesystem_support()
return fs ;
}
-void reiserfs::set_used_sectors( Partition & partition )
+void reiserfs::set_used_sectors( Partition & partition )
{
- if ( ! Utils::execute_command( "debugreiserfs " + partition .get_path(), output, error, true ) )
- {
- index = output .find( "Blocksize" ) ;
- if ( index >= output .length() ||
- sscanf( output .substr( index ) .c_str(), "Blocksize: %Ld", &S ) != 1 )
- S = -1 ;
+ set_used_sectors( partition, unlock_mutex );
+ mutex.lock();
+}
- index = output .find( ":", output .find( "Free blocks" ) ) +1 ;
- if ( index >= output .length() ||
- sscanf( output .substr( index ) .c_str(), "%Ld", &N ) != 1 )
- N = -1 ;
+void reiserfs::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "debugreiserfs " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiserfs::set_used_sectors2 ),
+ &partition ) );
+}
+bool reiserfs::set_used_sectors2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
+ {
+ index = output.find( "Blocksize" );
+ if ( index >= output.length() ||
+ sscanf( output.substr( index ).c_str(), "Blocksize: %Ld", &S ) != 1 )
+ S = -1;
+ index = output.find( ":", output.find( "Free blocks" ) ) + 1;
+ if ( index >= output.length() ||
+ sscanf( output.substr( index ).c_str(), "%Ld", &N ) != 1 )
+ N = -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 reiserfs::read_label( Partition & partition )
{
+ read_label( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void reiserfs::read_label( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
//FIXME: i think running debugreiserfs takes a long time on filled file systems, test for this...
- if ( ! Utils::execute_command( "debugreiserfs " + partition .get_path(), output, error, true ) )
+ execute_command( "debugreiserfs " + partition.get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiserfs::read_label2 ),
+ &partition ) );
+}
+
+bool reiserfs::read_label2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .label = Utils::regexp_label( output, "^label:[\t ]*(.*)$" ) ;
+ partition->label = Utils::regexp_label( output, "^label:[\t ]*(.*)$" );
}
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 reiserfs::write_label( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "reiserfstune --label \"" + partition .label + "\" " + partition .get_path(), operationdetail ) ;
+ write_label( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiserfs::write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "reiserfstune --label \"" + partition .label + "\" " + partition .get_path(),
+ operationdetail,
+ set_success );
}
void reiserfs::read_uuid( Partition & partition )
{
- if ( ! Utils::execute_command( "reiserfstune " + partition .get_path(), output, error, true ) )
+ read_uuid( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void reiserfs::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "reiserfstune " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &reiserfs::read_uuid2 ),
+ &partition ) );
+}
+
+bool reiserfs::read_uuid2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- partition .uuid = Utils::regexp_label( output, "^UUID:[[:blank:]]*([^[:space:]]*)" ) ;
+ partition->uuid = Utils::regexp_label( output, "^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 reiserfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
- return ! execute_command( "reiserfstune -u random " + partition .get_path(), operationdetail ) ;
+ write_uuid( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiserfs::write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "reiserfstune -u random " + partition.get_path(),
+ operationdetail,
+ set_success );
}
bool reiserfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
- return ! execute_command( "mkreiserfs -f --label \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ;
+ create( new_partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiserfs::create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "mkreiserfs -f --label \"" + new_partition .label + "\" " + new_partition.get_path(),
+ operationdetail,
+ set_success );
}
bool reiserfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
-{
+{
+ resize( partition_new, operationdetail, fill_partition, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiserfs::resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
Glib::ustring str_temp = "echo y | resize_reiserfs " + partition_new .get_path() ;
-
- if ( ! fill_partition )
+
+ 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 );
}
+ execute_command( str_temp, operationdetail, sigc::mem_fun( *this, &reiserfs::resize2 ) );
+}
- exit_status = execute_command( str_temp, operationdetail ) ;
-
- return ( exit_status == 0 || exit_status == 256 ) ;
+bool reiserfs::resize2( double progress )
+{
+ if ( progress != 1.0 )
+ return false;
+ success = ( exit_status == 0 || exit_status == 256 );
+ return slot( 1.0 );
}
bool reiserfs::move( const Partition & partition_new
@@ -166,6 +256,11 @@ bool reiserfs::move( const Partition & partition_new
return true ;
}
+void reiserfs::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool reiserfs::copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
@@ -173,11 +268,32 @@ bool reiserfs::copy( const Glib::ustring & src_part_path,
return true ;
}
+void reiserfs::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool reiserfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
- exit_status = execute_command( "reiserfsck --yes --fix-fixable --quiet " + partition .get_path(), operationdetail ) ;
-
- return ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) ;
+ check_repair( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void reiserfs::check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "reiserfsck --yes --fix-fixable --quiet " + partition.get_path(),
+ operationdetail,
+ sigc::mem_fun( *this, &reiserfs::check_repair2 ) );
+}
+
+bool reiserfs::check_repair2( double progress )
+{
+ if ( progress != 1.0 )
+ return false;
+ success = ( exit_status == 0 || exit_status == 1 || exit_status == 256 );
+ return slot( 1.0 );
}
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]