diff --git a/src/modules/partition/jobs/DeletePartitionJob.cpp b/src/modules/partition/jobs/DeletePartitionJob.cpp index 913fd8cd6..a678b5e90 100644 --- a/src/modules/partition/jobs/DeletePartitionJob.cpp +++ b/src/modules/partition/jobs/DeletePartitionJob.cpp @@ -10,6 +10,7 @@ */ #include "DeletePartitionJob.h" +#include "utils/CalamaresUtilsSystem.h" // KPMcore #include @@ -19,6 +20,45 @@ #include #include +#include + +/** @brief Determine if the given partition is of type Zfs + * + * Returns true if @p partition is of type Zfs + * + */ +static bool +isZfs( Partition* partition ) +{ + return partition->fileSystem().type() == FileSystem::Type::Zfs; +} + +/** @brief Remove the given partition manually + * + * Uses sfdisk to remove @p partition. This should only be used in cases + * where using kpmcore to remove the partition would not be appropriate + * + */ +static Calamares::JobResult +removePartition( Partition* partition ) +{ + auto r = CalamaresUtils::System::instance()->runCommand( + { "sfdisk", "--delete", "--force", partition->devicePath(), QString::number( partition->number() ) }, + std::chrono::seconds( 5 ) ); + if ( r.getExitCode() !=0 || r.getOutput().contains("failed") ) + { + return Calamares::JobResult::error( + QCoreApplication::translate( DeletePartitionJob::staticMetaObject.className(), "Deletion Failed" ), + QCoreApplication::translate( DeletePartitionJob::staticMetaObject.className(), + "Failed to delete the partition with output: " ) + + r.getOutput() ); + } + else + { + return Calamares::JobResult::ok(); + } +} + DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition ) : PartitionJob( partition ) , m_device( device ) @@ -49,6 +89,13 @@ DeletePartitionJob::prettyStatusMessage() const Calamares::JobResult DeletePartitionJob::exec() { + // The current implementation of remove() for zfs in kpmcore trys to destroy the zpool by label + // This isn't what we want here so we delete the partition instead. + if ( isZfs( m_partition ) ) + { + return removePartition( m_partition ); + } + Report report( nullptr ); DeleteOperation op( *m_device, m_partition ); op.setStatus( Operation::StatusRunning );