[gparted] Display progress of NTFS file system specific copy operation (#762366)



commit 6d28a6207779a3964a0f6ff8ea03b89da3795af4
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Feb 13 15:13:33 2016 +0000

    Display progress of NTFS file system specific copy operation (#762366)
    
    Copying of ntfs is performed using ntfsclone, which writes progress
    indication to standard output like this:
    
        # ntfsclone -f /dev/sdb2 /dev/sdb1 2> /dev/null
        NTFS volume version: 3.1
        Cluster size       : 4096 bytes
        Current volume size: 21474832384 bytes (21475 MB)
        Current device size: 21474836480 bytes (21475 MB)
        Scanning volume ...
        100.00 percent completed
        Accounting clusters ...
        Space in use       : 1832 MB (8.5%)
        Cloning NTFS ...
        100.00 percent completed
        Syncing ...
    
    Add ntfsclone progress tracker for ntfsclone command.  Deliberately
    doesn't stop the progress bar.  See comment in ntfs::clone_progress()
    for the explanation.
    
    Bug 762366 - Add progress bar to NTFS file system specific copy method

 include/ntfs.h |    1 +
 src/ntfs.cc    |   20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/include/ntfs.h b/include/ntfs.h
index 351da10..5273be9 100644
--- a/include/ntfs.h
+++ b/include/ntfs.h
@@ -46,6 +46,7 @@ public:
 
 private:
        void resize_progress( OperationDetail *operationdetail );
+       void clone_progress( OperationDetail *operationdetail );
 };
 
 } //GParted
diff --git a/src/ntfs.cc b/src/ntfs.cc
index cf50ee3..0d46d24 100644
--- a/src/ntfs.cc
+++ b/src/ntfs.cc
@@ -260,7 +260,8 @@ bool ntfs::copy( const Partition & src_part,
 {
        return ! execute_command( "ntfsclone -f --overwrite " + dest_part.get_path() + " " + 
src_part.get_path(),
                                  operationdetail,
-                                 EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
+                                 EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT,
+                                 static_cast<StreamSlot>( sigc::mem_fun( *this, &ntfs::clone_progress ) ) );
 }
 
 bool ntfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
@@ -295,4 +296,21 @@ void ntfs::resize_progress( OperationDetail *operationdetail )
        }
 }
 
+void ntfs::clone_progress( OperationDetail *operationdetail )
+{
+       Glib::ustring line = Utils::last_line( output );
+       // Text progress on the LAST LINE looks like " 15.24 progress completed"
+       float percent;
+       if ( line.find( "percent completed" ) != line.npos && sscanf( line.c_str(), "%f", &percent ) == 1 )
+       {
+               operationdetail->run_progressbar( percent, 100.0 );
+       }
+       // Deliberately don't stop the progress bar when ntfsclone outputs "Syncing ..."
+       // at the end as that is considered a measured part of the copy operation.  The
+       // progress bar will wait at 100% (or just below) until the sync completes.  On
+       // spinning rust that is typically a few seconds and on SSDs it won't be noticed
+       // at all.  Instead it is left for execute_command(), which always stops the
+       // progress bar when the command finishes.
+}
+
 } //GParted


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