[gparted] Stop relying on sort order when adding real paths in calibrate (#766349)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Stop relying on sort order when adding real paths in calibrate (#766349)
- Date: Fri, 20 May 2016 16:05:40 +0000 (UTC)
commit b77fef0dd5a85277210ca0cced77cc8abba99c8f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sat May 14 20:25:39 2016 +0100
Stop relying on sort order when adding real paths in calibrate (#766349)
Quoting the relevant comments from GParted_Core::calibrate_partition():
Re-add the real partition path from libparted.
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/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.
Having a separate display path is overly complicated and unnecessary.
Just replace the list of paths with the real one reported by libparted
if it contained "Copy of /dev/SRC", determined by checking if the file
exists. Otherwise continue to add the libparted name as an alternate
path. Whole disk devices can never be named "Copy of /dev/SRC" because
they are not partitioned so never created or deleted by GParted, only
ever written to, hence don't need the extra exists test logic.
Bug 766349 - Resolve code ugliness with partition path getting set to
"copy of /dev/SRC"
src/GParted_Core.cc | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 55abe27..35d3168 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3431,7 +3431,8 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
{
if ( partition .type == TYPE_PRIMARY || partition .type == TYPE_LOGICAL || partition .type ==
TYPE_EXTENDED )
{
- operationdetail .add_child( OperationDetail( String::ucompose( _("calibrate %1"), partition
.get_path() ) ) ) ;
+ Glib::ustring curr_path = partition.get_path();
+ operationdetail.add_child( OperationDetail( String::ucompose( _("calibrate %1"), curr_path )
) );
bool success = false;
PedDevice* lp_device = NULL ;
@@ -3442,9 +3443,9 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
{
// Virtual partition spanning whole disk device
- // Re-add the real partition path from libparted.
- // (See just below for why this is needed).
- partition.add_path( lp_device->path );
+ // Re-add alternate path from libparted if different.
+ if ( curr_path != lp_device->path )
+ partition.add_path( lp_device->path );
success = true;
}
@@ -3475,13 +3476,18 @@ bool GParted_Core::calibrate_partition( Partition & partition, OperationDetail &
// 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/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.
- partition.add_path( get_partition_path( lp_partition ) );
+ Glib::ustring new_path = get_partition_path( lp_partition );
+ if ( curr_path != new_path )
+ {
+ if ( ! file_test( curr_path, Glib::FILE_TEST_EXISTS ) )
+ // Current path doesn't exist, so assume
+ // it's "Copy of /dev/SRC" and replace
+ // with real path from libparted.
+ partition.add_path( new_path, true );
+ else
+ // Add alternate path from libparted.
+ partition.add_path( new_path );
+ }
// Reload the partition boundaries from libparted
// to ensure that GParted knows what the actual
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]