From 9436c18f69ac85f4ea0cbf40b24132d9077fba21 Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Thu, 15 Apr 2010 10:38:48 +0000 Subject: [PATCH] Do not create a temporary Partition instance for resizing. This does not work anymore because when aligning the resized partition it is no longer known if an existing partition is the source of the temporary copy or some other partition. Let the ResizeDialog modify the original and restore its start and end sector after the dialog has been executed instead. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1115133 --- src/core/partition.h | 2 ++ src/gui/partitionmanagerwidget.cpp | 38 +++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/core/partition.h b/src/core/partition.h index 65be6dd..35b5a86 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -40,6 +40,7 @@ class InsertDialog; class NewDialog; class EditMountPointDialog; class PartPropsDialog; +class PartitionManagerWidget; class CreateFileSystemOperation; class RestoreOperation; @@ -84,6 +85,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode friend class NewDialog; friend class EditMountPointDialog; friend class PartPropsDialog; + friend class PartitionManagerWidget; friend class CreateFileSystemOperation; friend class RestoreOperation; diff --git a/src/gui/partitionmanagerwidget.cpp b/src/gui/partitionmanagerwidget.cpp index 0e28bd3..0d2dff5 100644 --- a/src/gui/partitionmanagerwidget.cpp +++ b/src/gui/partitionmanagerwidget.cpp @@ -552,18 +552,40 @@ void PartitionManagerWidget::onResizePartition() return; } - const qint64 freeBefore = selectedDevice()->partitionTable()->freeSectorsBefore(*selectedPartition()); - const qint64 freeAfter = selectedDevice()->partitionTable()->freeSectorsAfter(*selectedPartition()); + // we cannot work with selectedPartition() here because opening and closing the dialog will + // clear the selection, so we'll lose the partition after the dialog's been exec'd + Partition& p = *selectedPartition(); - Partition resizedPartition(*selectedPartition()); - QPointer dlg = new ResizeDialog(this, *selectedDevice(), resizedPartition, selectedPartition()->firstSector() - freeBefore, freeAfter + selectedPartition()->lastSector()); + const qint64 freeBefore = selectedDevice()->partitionTable()->freeSectorsBefore(p); + const qint64 freeAfter = selectedDevice()->partitionTable()->freeSectorsAfter(p); - if (dlg->exec() == KDialog::Accepted && dlg->isModified()) + // in 1.0.x we used to copy the selected partition to a temporary Partition object and + // pass that to the ResizeDialog. This leads to problems with PartitionAlignment + // having to find out if a sector is occupied by another partition or by the original + // partition we did copy from here. Thus we don't do that anymore but modify the original + // partition and revert the modifications again before setting upt the ResizeOperation. + const qint64 originalFirst = p.firstSector(); + const qint64 originalLast = p.lastSector(); + + QPointer dlg = new ResizeDialog(this, *selectedDevice(), p, p.firstSector() - freeBefore, freeAfter + p.lastSector()); + + int status = dlg->exec(); + + const qint64 resizedFirst = p.firstSector(); + const qint64 resizedLast = p.lastSector(); + + p.setFirstSector(originalFirst); + p.fileSystem().setFirstSector(originalFirst); + + p.setLastSector(originalLast); + p.fileSystem().setLastSector(originalLast); + + if (status == KDialog::Accepted) { - if (resizedPartition.firstSector() == selectedPartition()->firstSector() && resizedPartition.lastSector() == selectedPartition()->lastSector()) - Log(Log::information) << i18nc("@info/plain", "Partition %1 has the same position and size after resize/move. Ignoring operation.", selectedPartition()->deviceNode()); + if (resizedFirst == originalFirst && resizedLast == originalLast) + Log(Log::information) << i18nc("@info/plain", "Partition %1 has the same position and size after resize/move. Ignoring operation.", p.deviceNode()); else - operationStack().push(new ResizeOperation(*selectedDevice(), *selectedPartition(), resizedPartition.firstSector(), resizedPartition.lastSector())); + operationStack().push(new ResizeOperation(*selectedDevice(), p, resizedFirst, resizedLast)); } delete dlg;