Add LVM delete partition job
This commit is contained in:
parent
542db88336
commit
76800ea872
|
@ -241,3 +241,18 @@ qint32 LvmDevice::getTotalLE(const QString& lvpath)
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LvmDevice::removeLV(Device& dev, Partition& part)
|
||||||
|
{
|
||||||
|
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||||
|
{ QStringLiteral("lvremove"),
|
||||||
|
QStringLiteral("--yes"),
|
||||||
|
part.partitionPath()});
|
||||||
|
|
||||||
|
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||||
|
//TODO: remove Partition from PartitionTable and delete from memory
|
||||||
|
dev.partitionTable()->remove(&part);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@ public:
|
||||||
|
|
||||||
static qint32 getTotalLE(const QString& lvpath);
|
static qint32 getTotalLE(const QString& lvpath);
|
||||||
|
|
||||||
|
static bool removeLV(Device& dev, Partition& part);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initPartitions();
|
void initPartitions();
|
||||||
QList<QString> deviceNodeList() const override;
|
QList<QString> deviceNodeList() const override;
|
||||||
|
|
|
@ -63,8 +63,12 @@ bool DeleteFileSystemJob::run(Report& parent)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partition().roles().has(PartitionRole::Extended))
|
if (partition().roles().has(PartitionRole::Extended)) {
|
||||||
rval = true;
|
rval = true;
|
||||||
|
} else if (device().type() == Device::LVM_Device) {
|
||||||
|
//TODO: LVM delete Filesystem Job. libparted can't help us here.
|
||||||
|
rval = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (!partition().fileSystem().remove(*report, partition().deviceNode())) {
|
if (!partition().fileSystem().remove(*report, partition().deviceNode())) {
|
||||||
jobFinished(*report, rval);
|
jobFinished(*report, rval);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "core/partition.h"
|
#include "core/partition.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
|
#include "core/lvmdevice.h"
|
||||||
|
|
||||||
#include "util/report.h"
|
#include "util/report.h"
|
||||||
|
|
||||||
|
@ -56,27 +57,31 @@ bool DeletePartitionJob::run(Report& parent)
|
||||||
|
|
||||||
Report* report = jobStarted(parent);
|
Report* report = jobStarted(parent);
|
||||||
|
|
||||||
CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode());
|
if (device().type() == Device::Disk_Device) {
|
||||||
|
CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode());
|
||||||
|
|
||||||
if (backendDevice) {
|
if (backendDevice) {
|
||||||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
||||||
|
|
||||||
if (backendPartitionTable) {
|
if (backendPartitionTable) {
|
||||||
rval = backendPartitionTable->deletePartition(*report, partition());
|
rval = backendPartitionTable->deletePartition(*report, partition());
|
||||||
|
|
||||||
if (!rval)
|
if (!rval)
|
||||||
report->line() << xi18nc("@info:progress", "Could not delete partition <filename>%1</filename>.", partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Could not delete partition <filename>%1</filename>.", partition().deviceNode());
|
||||||
else
|
else
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
delete backendPartitionTable;
|
delete backendPartitionTable;
|
||||||
|
|
||||||
|
} else
|
||||||
|
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||||
|
|
||||||
|
delete backendDevice;
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device <filename>%1</filename>.", device().deviceNode());
|
||||||
|
} else if (device().type() == Device::LVM_Device) {
|
||||||
delete backendDevice;
|
rval = LvmDevice::removeLV(device(), partition());
|
||||||
} else
|
}
|
||||||
report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device <filename>%1</filename>.", device().deviceNode());
|
|
||||||
|
|
||||||
jobFinished(*report, rval);
|
jobFinished(*report, rval);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue