From 24c1bf429e9117d58071abfc051ee679d045c1c8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 10 Mar 2016 12:33:19 +0100 Subject: [PATCH] Don't fail when trying to replace unallocated space. --- src/modules/partition/core/PartitionActions.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 559ced9a6..67d73782f 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -201,10 +201,23 @@ void doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition ) { cDebug() << "doReplacePartition for device" << partition->partitionPath(); + PartitionRole newRoles( partition->roles() ); if ( partition->roles().has( PartitionRole::Extended ) ) newRoles = PartitionRole( PartitionRole::Primary ); + if ( partition->roles().has( PartitionRole::Unallocated ) ) + { + newRoles = PartitionRole( PartitionRole::Primary ); + cDebug() << "WARNING: selected partition is free space"; + if ( partition->parent() ) + { + Partition* parent = dynamic_cast< Partition* >( partition->parent() ); + if ( parent && parent->roles().has( PartitionRole::Extended ) ) + newRoles = PartitionRole( PartitionRole::Logical ); + } + } + Partition* newPartition = KPMHelpers::createNewPartition( partition->parent(), *dev, @@ -215,7 +228,8 @@ doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition PartitionInfo::setMountPoint( newPartition, "/" ); PartitionInfo::setFormat( newPartition, true ); - core->deletePartition( dev, partition ); + if ( !partition->roles().has( PartitionRole::Unallocated ) ) + core->deletePartition( dev, partition ); core->createPartition( dev, newPartition ); core->dumpQueue();