From e792f4c9c5805ebf16e0a6174cc4d631d8c5a424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 10 Jul 2014 15:07:02 +0200 Subject: [PATCH] Implement DeletePartitionJob::exec() Closes #11 --- src/modules/partition/DeletePartitionJob.cpp | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/modules/partition/DeletePartitionJob.cpp b/src/modules/partition/DeletePartitionJob.cpp index 157b17c2f..a3b96e163 100644 --- a/src/modules/partition/DeletePartitionJob.cpp +++ b/src/modules/partition/DeletePartitionJob.cpp @@ -19,10 +19,15 @@ #include // CalaPM +#include +#include +#include +#include #include #include #include #include +#include DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition ) : m_device( device ) @@ -39,6 +44,48 @@ DeletePartitionJob::prettyName() const Calamares::JobResult DeletePartitionJob::exec() { + Report report( 0 ); + QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() ); + + 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 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 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(); }