diff --git a/src/ops/operation.cpp b/src/ops/operation.cpp index c837f29..d575fb9 100644 --- a/src/ops/operation.cpp +++ b/src/ops/operation.cpp @@ -20,6 +20,7 @@ #include "core/partition.h" #include "core/device.h" +#include "core/lvmdevice.h" #include "jobs/job.h" @@ -51,6 +52,10 @@ void Operation::insertPreviewPartition(Device& device, Partition& p) device.partitionTable()->removeUnallocated(); p.parent()->insert(&p); + if (device.type() == Device::Type::LVM_Device) { + const LvmDevice& lvm = static_cast(device); + lvm.setFreePE(lvm.freePE() - p.length()); + } device.partitionTable()->updateUnallocated(device); } @@ -59,8 +64,14 @@ void Operation::removePreviewPartition(Device& device, Partition& p) { Q_ASSERT(device.partitionTable()); - if (p.parent()->remove(&p)) + if (p.parent()->remove(&p)) { + if (device.type() == Device::Type::LVM_Device) { + const LvmDevice& lvm = static_cast(device); + lvm.setFreePE(lvm.freePE() + p.length()); + } + device.partitionTable()->updateUnallocated(device); + } else qWarning() << "failed to remove partition " << p.deviceNode() << " at " << &p << " from preview."; } diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index fee9207..3527a96 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -121,11 +121,6 @@ bool ResizeOperation::targets(const Partition& p) const void ResizeOperation::preview() { - if (targetDevice().type() == Device::Type::LVM_Device) { - const LvmDevice& lvm = static_cast(targetDevice()); - lvm.setFreePE(lvm.freePE() + partition().lastSector() - newLastSector()); - } - // If the operation has already been executed, the partition will of course have newFirstSector and // newLastSector as first and last sector. But to remove it from its original position, we need to // temporarily set these values back to where they were before the operation was executed. @@ -144,11 +139,6 @@ void ResizeOperation::preview() void ResizeOperation::undo() { - if (targetDevice().type() == Device::Type::LVM_Device) { - const LvmDevice& lvm = static_cast(targetDevice()); - lvm.setFreePE(lvm.freePE() - origLastSector() + partition().lastSector()); - } - removePreviewPartition(targetDevice(), partition()); partition().setFirstSector(origFirstSector()); partition().setLastSector(origLastSector());