Skip to content
Snippets Groups Projects
Commit fd8c131b authored by Chantara Tith's avatar Chantara Tith
Browse files

implement free-space partition replace install

parent bb081c91
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,6 @@ namespace PartUtils ...@@ -37,9 +37,6 @@ namespace PartUtils
bool bool
canBeReplaced( Partition* candidate ) canBeReplaced( Partition* candidate )
{ {
if ( KPMHelpers::isPartitionFreeSpace( candidate ) )
return false;
bool ok = false; bool ok = false;
double requiredStorageGB = Calamares::JobQueue::instance() double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage() ->globalStorage()
......
...@@ -579,22 +579,49 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current, ...@@ -579,22 +579,49 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current,
m_core->revertDevice( selectedDevice() ); m_core->revertDevice( selectedDevice() );
} }
// TODO: get the selected partition in the immutable model with PartitionPtrRole, // if the partition is unallocated(free space), we don't replace it but create new one
// check KPMHelpers::isPartitionFreeSpace, if true then don't replace but // with the same first and last sector
// just m_core->createPartition for the same first/last sector as the Partition* selectedPartition = (Partition *)( current.data( PartitionModel::PartitionPtrRole ).value< void* >() );
// free space "partition" in the immutable model. if ( KPMHelpers::isPartitionFreeSpace( selectedPartition ) )
// Also set parent correctly (see PartitionActions::doReplacePartition) {
// as well as mount point and format. PartitionRole newRoles = PartitionRole( PartitionRole::Primary );
PartitionNode* newParent = selectedDevice()->partitionTable();
// We can't use the PartitionPtrRole because we need to make changes to the
// main DeviceModel, not the immutable copy. if ( selectedPartition->parent() )
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString(); {
Partition* partition = KPMHelpers::findPartitionByPath( { selectedDevice() }, Partition* parent = dynamic_cast< Partition* >( selectedPartition->parent() );
partPath ); if ( parent && parent->roles().has( PartitionRole::Extended ) )
if ( partition ) {
PartitionActions::doReplacePartition( m_core, newRoles = PartitionRole( PartitionRole::Logical );
selectedDevice(), newParent = KPMHelpers::findPartitionByPath( { selectedDevice() }, parent->partitionPath() );
partition ); }
}
Partition* newPartition = KPMHelpers::createNewPartition(
newParent,
*selectedDevice(),
newRoles,
FileSystem::Ext4,
selectedPartition->firstSector(),
selectedPartition->lastSector() );
PartitionInfo::setMountPoint( newPartition, "/" );
PartitionInfo::setFormat( newPartition, true );
m_core->createPartition( selectedDevice(), newPartition);
}
else
{
// We can't use the PartitionPtrRole because we need to make changes to the
// main DeviceModel, not the immutable copy.
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
selectedPartition = KPMHelpers::findPartitionByPath( { selectedDevice() },
partPath );
if ( selectedPartition )
PartitionActions::doReplacePartition( m_core,
selectedDevice(),
selectedPartition );
}
} ), } ),
[=] [=]
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment