A mounted partition cannot be resized or replaced

- add check for isMounted()
 - a device with a mounted partition cannot be (entirely) erased

FIXES #639
This commit is contained in:
Adriaan de Groot 2017-09-07 04:55:26 -04:00 committed by Philip
parent d348633b14
commit 9b8a194e39
2 changed files with 26 additions and 50 deletions

View File

@ -45,6 +45,9 @@ canBeReplaced( Partition* candidate )
if ( !candidate ) if ( !candidate )
return false; return false;
if ( candidate->isMounted() )
return false;
bool ok = false; bool ok = false;
double requiredStorageGB = Calamares::JobQueue::instance() double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage() ->globalStorage()
@ -83,6 +86,9 @@ canBeResized( Partition* candidate )
if ( KPMHelpers::isPartitionFreeSpace( candidate ) ) if ( KPMHelpers::isPartitionFreeSpace( candidate ) )
return false; return false;
if ( candidate->isMounted() )
return false;
if ( candidate->roles().has( PartitionRole::Primary ) ) if ( candidate->roles().has( PartitionRole::Primary ) )
{ {
PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() ); PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() );

View File

@ -1130,6 +1130,15 @@ ChoicePage::createBootloaderComboBox( QWidget* parent )
} }
static inline void
force_uncheck(QButtonGroup* grp, PrettyRadioButton* button)
{
button->hide();
grp->setExclusive( false );
button->buttonWidget()->setChecked( false );
grp->setExclusive( true );
}
/** /**
* @brief ChoicePage::setupActions happens every time a new Device* is selected in the * @brief ChoicePage::setupActions happens every time a new Device* is selected in the
* device picker. Sets up the text and visibility of the partitioning actions based * device picker. Sets up the text and visibility of the partitioning actions based
@ -1149,30 +1158,20 @@ ChoicePage::setupActions()
m_deviceInfoWidget->setPartitionTableType( PartitionTable::unknownTableType ); m_deviceInfoWidget->setPartitionTableType( PartitionTable::unknownTableType );
bool atLeastOneCanBeResized = false; bool atLeastOneCanBeResized = false;
bool atLeastOneCanBeReplaced = false;
bool atLeastOneIsMounted = false; // Suppress 'erase' if so
for ( auto it = PartitionIterator::begin( currentDevice ); for ( auto it = PartitionIterator::begin( currentDevice );
it != PartitionIterator::end( currentDevice ); ++it ) it != PartitionIterator::end( currentDevice ); ++it )
{ {
if ( PartUtils::canBeResized( *it ) ) if ( PartUtils::canBeResized( *it ) )
{
atLeastOneCanBeResized = true; atLeastOneCanBeResized = true;
break;
}
}
bool atLeastOneCanBeReplaced = false;
for ( auto it = PartitionIterator::begin( currentDevice );
it != PartitionIterator::end( currentDevice ); ++it )
{
if ( PartUtils::canBeReplaced( *it ) ) if ( PartUtils::canBeReplaced( *it ) )
{
atLeastOneCanBeReplaced = true; atLeastOneCanBeReplaced = true;
break; if ( (*it)->isMounted() )
} atLeastOneIsMounted = true;
} }
if ( osproberEntriesForCurrentDevice.count() == 0 ) if ( osproberEntriesForCurrentDevice.count() == 0 )
{ {
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
@ -1249,18 +1248,6 @@ ChoicePage::setupActions()
.arg( *Calamares::Branding::ShortVersionedName ) ); .arg( *Calamares::Branding::ShortVersionedName ) );
) )
} }
m_replaceButton->show();
if ( atLeastOneCanBeResized )
m_alongsideButton->show();
else
{
m_alongsideButton->hide();
m_grp->setExclusive( false );
m_alongsideButton->buttonWidget()->setChecked( false );
m_grp->setExclusive( true );
}
} }
else else
{ {
@ -1284,39 +1271,22 @@ ChoicePage::setupActions()
"Replaces a partition with %1." ) "Replaces a partition with %1." )
.arg( *Calamares::Branding::ShortVersionedName ) ); .arg( *Calamares::Branding::ShortVersionedName ) );
) )
m_replaceButton->show();
if ( atLeastOneCanBeResized )
m_alongsideButton->show();
else
{
m_alongsideButton->hide();
m_grp->setExclusive( false );
m_alongsideButton->buttonWidget()->setChecked( false );
m_grp->setExclusive( true );
}
} }
if ( atLeastOneCanBeReplaced ) if ( atLeastOneCanBeReplaced )
m_replaceButton->show(); m_replaceButton->show();
else else
{ force_uncheck( m_grp, m_replaceButton );
m_replaceButton->hide();
m_grp->setExclusive( false );
m_replaceButton->buttonWidget()->setChecked( false );
m_grp->setExclusive( true );
}
if ( atLeastOneCanBeResized ) if ( atLeastOneCanBeResized )
m_alongsideButton->show(); m_alongsideButton->show();
else else
{ force_uncheck( m_grp, m_alongsideButton );
m_alongsideButton->hide();
m_grp->setExclusive( false ); if ( !atLeastOneIsMounted )
m_alongsideButton->buttonWidget()->setChecked( false ); m_eraseButton->show(); // None mounted
m_grp->setExclusive( true ); else
} force_uncheck( m_grp, m_eraseButton );
bool isEfi = PartUtils::isEfiSystem(); bool isEfi = PartUtils::isEfiSystem();
bool efiSystemPartitionFound = !m_core->efiSystemPartitions().isEmpty(); bool efiSystemPartitionFound = !m_core->efiSystemPartitions().isEmpty();