Skip to content

Commit

Permalink
A mounted partition cannot be resized or replaced
Browse files Browse the repository at this point in the history
 - add check for isMounted()
 - a device with a mounted partition cannot be (entirely) erased

FIXES #639
  • Loading branch information
adriaandegroot committed Sep 7, 2017
1 parent 8513796 commit 3e59161
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 50 deletions.
6 changes: 6 additions & 0 deletions src/modules/partition/core/PartUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ canBeReplaced( Partition* candidate )
if ( !candidate )
return false;

if ( candidate->isMounted() )
return false;

bool ok = false;
double requiredStorageGB = Calamares::JobQueue::instance()
->globalStorage()
Expand Down Expand Up @@ -83,6 +86,9 @@ canBeResized( Partition* candidate )
if ( KPMHelpers::isPartitionFreeSpace( candidate ) )
return false;

if ( candidate->isMounted() )
return false;

if ( candidate->roles().has( PartitionRole::Primary ) )
{
PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() );
Expand Down
70 changes: 20 additions & 50 deletions src/modules/partition/gui/ChoicePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
* device picker. Sets up the text and visibility of the partitioning actions based
Expand All @@ -1149,30 +1158,20 @@ ChoicePage::setupActions()
m_deviceInfoWidget->setPartitionTableType( PartitionTable::unknownTableType );

bool atLeastOneCanBeResized = false;
bool atLeastOneCanBeReplaced = false;
bool atLeastOneIsMounted = false; // Suppress 'erase' if so

for ( auto it = PartitionIterator::begin( currentDevice );
it != PartitionIterator::end( currentDevice ); ++it )
{
if ( PartUtils::canBeResized( *it ) )
{
atLeastOneCanBeResized = true;
break;
}
}

bool atLeastOneCanBeReplaced = false;

for ( auto it = PartitionIterator::begin( currentDevice );
it != PartitionIterator::end( currentDevice ); ++it )
{
if ( PartUtils::canBeReplaced( *it ) )
{
atLeastOneCanBeReplaced = true;
break;
}
if ( (*it)->isMounted() )
atLeastOneIsMounted = true;
}


if ( osproberEntriesForCurrentDevice.count() == 0 )
{
CALAMARES_RETRANSLATE(
Expand Down Expand Up @@ -1249,18 +1248,6 @@ ChoicePage::setupActions()
.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
{
Expand All @@ -1284,39 +1271,22 @@ ChoicePage::setupActions()
"Replaces a partition with %1." )
.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 )
m_replaceButton->show();
else
{
m_replaceButton->hide();
m_grp->setExclusive( false );
m_replaceButton->buttonWidget()->setChecked( false );
m_grp->setExclusive( true );
}
force_uncheck( m_grp, m_replaceButton );

if ( atLeastOneCanBeResized )
m_alongsideButton->show();
else
{
m_alongsideButton->hide();
m_grp->setExclusive( false );
m_alongsideButton->buttonWidget()->setChecked( false );
m_grp->setExclusive( true );
}
force_uncheck( m_grp, m_alongsideButton );

if ( !atLeastOneIsMounted )
m_eraseButton->show(); // None mounted
else
force_uncheck( m_grp, m_eraseButton );

bool isEfi = PartUtils::isEfiSystem();
bool efiSystemPartitionFound = !m_core->efiSystemPartitions().isEmpty();
Expand Down

0 comments on commit 3e59161

Please sign in to comment.