[gparted] Display progress for e2fsck (#467925)



commit ae434579e160ca2c306921b12d4211bf9abacef7
Author: Phillip Susi <psusi ubuntu com>
Date:   Sat Mar 2 17:57:34 2013 -0500

    Display progress for e2fsck (#467925)
    
    Parse output and update progress bar.
    
    Bug 467925 - gparted: add progress bar during operation

 include/ext2.h |    1 +
 src/ext2.cc    |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/include/ext2.h b/include/ext2.h
index fddf48f..7c9e4ba 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -56,6 +56,7 @@ public:
 private:
        void resize_progress( OperationDetail *operationdetail );
        void create_progress( OperationDetail *operationdetail );
+       void check_repair_progress( OperationDetail *operationdetail );
 };
 
 } //GParted
diff --git a/src/ext2.cc b/src/ext2.cc
index 6a11db5..07e136c 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -244,8 +244,10 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd
 
 bool ext2::check_repair( const Partition & partition, OperationDetail & operationdetail )
 {
+       sigc::connection c = signal_progress.connect( sigc::mem_fun( *this, &ext2::check_repair_progress ) );
        exit_status = execute_command( fsck_cmd + " -f -y -v -C 0 " + partition.get_path(), operationdetail,
                                       EXEC_CANCEL_SAFE );
+       c.disconnect();
        bool success = ( exit_status == 0 || exit_status == 1 || exit_status == 2 );
        set_status( operationdetail, success );
        return success;
@@ -323,4 +325,24 @@ void ext2::create_progress( OperationDetail *operationdetail )
        }
 }
 
+void ext2::check_repair_progress( OperationDetail *operationdetail )
+{
+       Glib::ustring ss;
+       size_t p = output.find_last_of('\n');
+       // looks like "/dev/loop0p1: |==============================================  \ 95.1%"
+       if ( p == output.npos )
+               return;
+       ss = output.substr( p );
+       p = ss.find_last_of('%');
+       if ( p == ss.npos )
+               return;
+       ss = ss.substr( p-5, p );
+       float frac;
+       if ( sscanf( ss.c_str(), "%f%%", &frac ) == 1 )
+       {
+               operationdetail->fraction = frac / 100;
+               operationdetail->signal_update( *operationdetail );
+       }
+}
+
 } //GParted


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]