Use KPMcore DeleteOperation to delete partitions.

This commit is contained in:
Andrius Štikonas 2017-10-12 18:59:11 +01:00
parent 70573543f2
commit ceba157459

View File

@ -29,6 +29,7 @@
#include <kpmcore/core/partition.h>
#include <kpmcore/core/partitiontable.h>
#include <kpmcore/fs/filesystem.h>
#include <kpmcore/ops/deleteoperation.h>
#include <kpmcore/util/report.h>
DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition )
@ -65,48 +66,14 @@ Calamares::JobResult
DeletePartitionJob::exec()
{
Report report( nullptr );
DeleteOperation op(*m_device, m_partition);
op.setStatus(Operation::StatusRunning);
QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() );
if (op.execute(report))
return Calamares::JobResult::ok();
if ( m_device->deviceNode() != m_partition->devicePath() )
{
return Calamares::JobResult::error(
message,
tr( "Partition (%1) and device (%2) do not match." )
.arg( m_partition->devicePath() )
.arg( m_device->deviceNode() )
);
}
CoreBackend* backend = CoreBackendManager::self()->backend();
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
if ( !backendDevice.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open device %1." ).arg( m_device->deviceNode() )
);
}
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
if ( !backendPartitionTable.data() )
{
return Calamares::JobResult::error(
message,
tr( "Could not open partition table." )
);
}
bool ok = backendPartitionTable->deletePartition( report, *m_partition );
if ( !ok )
{
return Calamares::JobResult::error(
message,
report.toText()
);
}
backendPartitionTable->commit();
return Calamares::JobResult::ok();
return Calamares::JobResult::error(message, report.toText());
}
void