[gparted] Update ext2 fsck progress tracker to use the new ProgressBar (#760709)



commit 97f836869f29c6748172af2ee9a22b8d34668899
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Jan 13 22:57:04 2016 +0000

    Update ext2 fsck progress tracker to use the new ProgressBar (#760709)
    
    Adapt the ext2 fsck progress tracker to use the new ProgressBar class.
    Also make it track when the text progress bar has completely passed in
    the output so that the progress bar can be stopped as well as started
    when needed.
    
    Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
                 copy methods

 src/ext2.cc |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/src/ext2.cc b/src/ext2.cc
index e3b0b52..d68d113 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -347,20 +347,30 @@ 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 )
+       ProgressBar & progressbar = operationdetail->get_progressbar();
+       Glib::ustring line = Utils::last_line( output );
+       // Text progress on the LAST LINE looks like
+       // "/dev/sdd3: |=====================================================   \ 95.1%   "
+       size_t p = line.rfind( "%" );
+       Glib::ustring pct;
+       if ( p != line.npos && p >= 5 )
+               pct = line.substr( p-5, 6 );
+       float progress;
+       if ( line.find( ": |" ) != line.npos && sscanf( pct.c_str(), "%f", &progress ) == 1 )
+       {
+               if ( ! progressbar.running() )
+                       progressbar.start( 100.0 );
+               progressbar.update( progress );
+               operationdetail->signal_update( *operationdetail );
+       }
+       // Only allow stopping the progress bar after seeing "non-contiguous" in the
+       // summary at the end to prevent the GUI progress bar flashing back to pulsing
+       // mode when the text progress bar is temporarily missing/incomplete before fsck
+       // output is fully updated when switching from one pass to the next.
+       else if ( output.find( "non-contiguous" ) != output.npos )
        {
-               operationdetail->fraction = frac / 100;
+               if ( progressbar.running() )
+                       progressbar.stop();
                operationdetail->signal_update( *operationdetail );
        }
 }


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