diff --git a/src/ops/removevolumegroupoperation.cpp b/src/ops/removevolumegroupoperation.cpp index c680f47..e7eaf1f 100644 --- a/src/ops/removevolumegroupoperation.cpp +++ b/src/ops/removevolumegroupoperation.cpp @@ -18,6 +18,7 @@ #include "ops/removevolumegroupoperation.h" #include "jobs/removevolumegroupjob.h" +#include "core/partition.h" #include "core/partitiontable.h" #include "core/volumemanagerdevice.h" @@ -50,3 +51,24 @@ void RemoveVolumeGroupOperation::undo() { device().setPartitionTable(m_PartitionTable); } + +/** Check if Volume Group can be safely removed + * + * @param dev VolumeManagerDevice with initialized partitions + * @return true if there are no LVM partitions. + */ +bool RemoveVolumeGroupOperation::isRemovable(const VolumeManagerDevice* dev) +{ + // TODO: allow removal when LVs are inactive. + if (dev->type() == Device::LVM_Device) { + if (dev->partitionTable()->children().count() == 0) // This is necessary to prevent a crash during applying of operations + return true; + else if (dev->partitionTable()->children().count() > 1) + return false; + else + if (dev->partitionTable()->children().first()->fileSystem().type() == FileSystem::Unknown) + return true; + } + + return false; +} diff --git a/src/ops/removevolumegroupoperation.h b/src/ops/removevolumegroupoperation.h index 23cac18..c1e94f8 100644 --- a/src/ops/removevolumegroupoperation.h +++ b/src/ops/removevolumegroupoperation.h @@ -56,6 +56,8 @@ public: virtual void preview() override; virtual void undo() override; + static bool isRemovable(const VolumeManagerDevice* dev); + protected: RemoveVolumeGroupJob* removeVolumeGroupJob() { return m_RemoveVolumeGroupJob;