[gparted] Match up OperationDetail creation and status setting for internal copy (#790842)



commit ff0360eb4f571ce77ea9fc1c8ff774e416a6e34b
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Dec 8 18:55:24 2017 +0000

    Match up OperationDetail creation and status setting for internal copy (#790842)
    
    This is not required, but it is more logical to have an OperationDetail
    object created and it's final status set in the same function rather
    than split between caller and callee.  So move creation of
    "copy %1 using a block size of %2" OperationDetail objects into
    GParted_Core::copy().
    
    Also introduces a couple of variables to remove some recomputation:
    benchmark_od & remaining_length.
    
    Bug 790842 - Report libparted messages into operation details at the
                 point at which they occur

 src/CopyBlocks.cc   |    5 -----
 src/GParted_Core.cc |   21 +++++++++++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/src/CopyBlocks.cc b/src/CopyBlocks.cc
index f25c0c1..ff4a3ec 100644
--- a/src/CopyBlocks.cc
+++ b/src/CopyBlocks.cc
@@ -150,11 +150,6 @@ bool CopyBlocks::copy()
        if ( blocksize > length )
                blocksize = length;
 
-       operationdetail.add_child( OperationDetail(
-                       /*TO TRANSLATORS: looks like  copy 16.00 MiB using a block size of 1.00 MiB */
-                       String::ucompose( _("copy %1 using a block size of %2"),
-                                         Utils::format_size( length, 1 ),
-                                         Utils::format_size( blocksize, 1 ) ) ) );
        operationdetail.run_progressbar( (double)total_done, (double)total_length, 
PROGRESSBAR_TEXT_COPY_BYTES );
 
        done = length % blocksize;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index bde3c37..c454640 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3223,12 +3223,19 @@ bool GParted_Core::copy_blocks( const Glib::ustring & src_device,
        Glib::Timer timer ;
        double smallest_time = 1000000 ;
        bool succes = true ;
+       OperationDetail & benchmark_od = operationdetail.get_last_child();
 
        //Benchmark copy times using different block sizes to determine optimal size
        while ( succes &&
                llabs( done ) + N <= src_length && 
                benchmark_blocksize <= N )
        {
+               benchmark_od.add_child( OperationDetail(
+                               /*TO TRANSLATORS: looks like   copy 16.00 MiB using a block size of 1.00 MiB 
*/
+                               String::ucompose( _("copy %1 using a block size of %2"),
+                                                 Utils::format_size( N, 1 ),
+                                                 Utils::format_size( benchmark_blocksize, 1 ) ) ) );
+
                timer .reset() ;
                succes = CopyBlocks( src_device,
                                     dst_device,
@@ -3236,15 +3243,15 @@ bool GParted_Core::copy_blocks( const Glib::ustring & src_device,
                                     offset_write + (done / dst_sector_size),
                                     N,
                                     benchmark_blocksize,
-                                    operationdetail .get_last_child(),
+                                    benchmark_od,
                                     total_done,
                                     src_length,
                                     cancel_safe ).copy();
                timer.stop() ;
 
-               operationdetail .get_last_child() .get_last_child() .add_child( OperationDetail( 
+               benchmark_od.get_last_child().add_child( OperationDetail(
                        String::ucompose( _("%1 seconds"), timer .elapsed() ), STATUS_NONE, FONT_ITALIC ) ) ;
-               operationdetail.get_last_child().get_last_child().set_success_and_capture_errors( succes );
+               benchmark_od.get_last_child().set_success_and_capture_errors( succes );
 
                if ( timer .elapsed() <= smallest_time )
                {
@@ -3268,11 +3275,17 @@ bool GParted_Core::copy_blocks( const Glib::ustring & src_device,
 
        if ( succes && llabs( done ) < src_length )
        {
+               Byte_Value remaining_length = src_length - llabs( done );
+               operationdetail.add_child( OperationDetail(
+                               /*TO TRANSLATORS: looks like   copy 16.00 MiB using a block size of 1.00 MiB 
*/
+                               String::ucompose( _("copy %1 using a block size of %2"),
+                                                 Utils::format_size( remaining_length, 1 ),
+                                                 Utils::format_size( optimal_blocksize, 1 ) ) ) );
                succes = CopyBlocks( src_device,
                                     dst_device,
                                     src_start + ((done > 0 ? done : 0) / src_sector_size),
                                     dst_start + ((done > 0 ? done : 0) / dst_sector_size),
-                                    src_length - llabs( done ),
+                                    remaining_length,
                                     optimal_blocksize,
                                     operationdetail,
                                     total_done,


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