[gparted] Stop overriding real path when pasting into existing partitions (#766349)



commit 302cc8041e867d8fe9ad45c9d8b2d042a6cfbc74
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue May 10 16:11:36 2016 +0100

    Stop overriding real path when pasting into existing partitions (#766349)
    
    When composing a copy operation it always named the destination
    partition as "copy of /dev/SRC".  For the case of pasting into
    unallocated space creating a new partition this was the right thing to
    do as the partition doesn't yet exist so the path is not yet known.
    However for the case of pasting into an existing partition the path is
    known and replacing it with "copy of /dev/SRC" is wrong.  No other
    operation when operating on an existing partition changes it path.
    
    Given a set of existing partitions, sdb1 to sdb4, compose a set of copy
    operations as: copy sdb1 to sdb2, copy sdb2 to sdb3 and copy sdb3 to
    sdb4.  The displayed partitions before being applied become:
        /dev/sdb1
        copy of /dev/sdb1
        copy of copy of /dev/sdb1
        copy of copy of copy of /dev/sdb1
    And the pending operations are named:
        Copy /dev/sdb1 to /dev/sdb2
        Copy copy of /dev/sdb1 to /dev/sdb3
        Copy copy of copy of /dev/sdb1 to /sev/sdb4
    
    This is perverse.  In the case of pasting into an existing partition
    keep the real path name.  This keeps the partitions being displayed as:
        /dev/sdb1
        /dev/sdb2
        /dev/sdb3
        /dev/sdb4
    And the pending operations named as:
        Copy /dev/sdb1 to /dev/sdb2
        Copy /dev/sdb2 to /dev/sdb3
        Copy /dev/sdb3 to /dev/sdb4
    Much more understandable.
    
    Also switch to an upper case "C" in "Copy of /dev/SRC" as the temporary
    path name when pasting into unallocated space.  Finally update the
    comment in calibrate_partition() to describe the remaining cases when
    re-adding the path is still required.
    
    Bug 766349 - Resolve code ugliness with partition path getting set to
                 "copy of /dev/SRC"

 src/GParted_Core.cc  |   32 ++++++++++++++++----------------
 src/OperationCopy.cc |    3 ---
 src/Win_GParted.cc   |    9 +++++++++
 3 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index ed43fa3..55abe27 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3461,23 +3461,23 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
                                {
                                        // Re-add the real partition path from libparted.
                                        //
-                                       // When creating a copy operation the list of
-                                       // paths for the partition object was set to
-                                       // ["copy of /dev/SRC"] to display in the UI
-                                       // before the operations are applied.  When
-                                       // pasting into an existing partition, this
-                                       // re-adds the real path to the start of the list
-                                       // making it ["/dev/DST", "copy of /dev/SRC"].
-                                       // This provides the real path for any file system
-                                       // specific tools needed during the copy
-                                       // operation.  Such as file system check and grow
-                                       // steps added when the source and destination
-                                       // aren't identical sizes or when file system
-                                       // specific tools are used to perform the copy as
-                                       // for XFS or recent EXT2/3/4 tools.
+                                       // When creating a copy operation by pasting into
+                                       // unallocated space the list of paths for the
+                                       // partition object was set to
+                                       // ["Copy of /dev/SRC"] because the partition
+                                       // didn't yet exist before the operations were
+                                       // applied.  Additional operations on that new
+                                       // partition also got the list of paths set to
+                                       // ["Copy of /dev/SRC"].  This re-adds the real
+                                       // path to the start of the list making it
+                                       // ["/dev/NEW", "Copy of /dev/SRC"].  This
+                                       // provides the real path for file system specific
+                                       // tools used during those additional operations
+                                       // such mkfs for the format operation or fsck and
+                                       // others for the resize/move operation.
                                        //
-                                       // FIXME: Having this work just because "/dev/DST"
-                                       // happens to sort before "copy of /dev/SRC" is
+                                       // FIXME: Having this work just because "/dev/NEW"
+                                       // happens to sort before "Copy of /dev/SRC" is
                                        // ugly!  Probably have a separate display path
                                        // which can be changed at will without affecting
                                        // the list of real paths for the partition.
diff --git a/src/OperationCopy.cc b/src/OperationCopy.cc
index 1b7d540..b5cc59d 100644
--- a/src/OperationCopy.cc
+++ b/src/OperationCopy.cc
@@ -33,9 +33,6 @@ OperationCopy::OperationCopy( const Device & device,
        this->partition_original = partition_orig.clone();
        this->partition_new      = partition_new.clone();
        this->partition_copied   = partition_copied.clone();
-
-       this->partition_new->add_path(
-                       String::ucompose( _("copy of %1"), this->partition_copied->get_path() ), true );
 }
 
 OperationCopy::~OperationCopy()
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 0f183e6..6e250ee 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1857,6 +1857,15 @@ void Win_GParted::activate_paste()
                                                                           *copied_partition );
                                operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU );
 
+                               // When pasting into unallocated space set a temporary
+                               // path of "Copy of /dev/SRC" for display purposes until
+                               // the partition is created and the real path queried.
+                               OperationCopy * copy_op = static_cast<OperationCopy*>( operation );
+                               copy_op->get_partition_new().add_path(
+                                       String::ucompose( _("Copy of %1"),
+                                                         copy_op->get_partition_copied().get_path() ),
+                                       true );
+
                                Add_Operation( operation ) ;
                        }
                }


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