[partition] Merge pull request #1808 from dalto8/zfs-delete-fix

Fix for zfs partition deletion
This commit is contained in:
Adriaan de Groot 2021-10-30 14:44:39 +02:00 committed by GitHub
commit cd56bab622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@
*/
#include "DeletePartitionJob.h"
#include "utils/CalamaresUtilsSystem.h"
// KPMcore
#include <kpmcore/core/device.h>
@ -19,6 +20,45 @@
#include <kpmcore/ops/deleteoperation.h>
#include <kpmcore/util/report.h>
#include <QCoreApplication>
/** @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 );