[partition] Simplify flags calculations

- factor out the flags-we-want from the flags-we-already-have
 - the use of ->activeFlags() meant that the state on *disk* was
   being compared with the flags-we-want; if a partition was re-edited,
   then you couldn't change the flags back to the state-on-disk
   (eg. enable a flag, then change your mind and disable it).
 - set the flags before refreshing the partition, because the
   refresh checks for EFI bootability and that needs the new flags,
   not the old ones.
This commit is contained in:
Adriaan de Groot 2020-11-04 00:58:11 +01:00
parent 949e33f1e8
commit 85bb8c27b3

View File

@ -147,6 +147,9 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
: FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() ); : FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
} }
const auto resultFlags = newFlags();
const auto currentFlags = PartitionInfo::flags( m_partition );
if ( partResizedMoved ) if ( partResizedMoved )
{ {
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
@ -157,20 +160,20 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
fsType, fsType,
newFirstSector, newFirstSector,
newLastSector, newLastSector,
newFlags() ); resultFlags );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true ); PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition ); core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition ); core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() ); core->setPartitionFlags( m_device, newPartition, resultFlags );
} }
else else
{ {
core->resizePartition( m_device, m_partition, newFirstSector, newLastSector ); core->resizePartition( m_device, m_partition, newFirstSector, newLastSector );
if ( m_partition->activeFlags() != newFlags() ) if ( currentFlags != resultFlags )
{ {
core->setPartitionFlags( m_device, m_partition, newFlags() ); core->setPartitionFlags( m_device, m_partition, resultFlags );
} }
} }
} }
@ -183,9 +186,9 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
if ( m_partition->fileSystem().type() == fsType ) if ( m_partition->fileSystem().type() == fsType )
{ {
core->formatPartition( m_device, m_partition ); core->formatPartition( m_device, m_partition );
if ( m_partition->activeFlags() != newFlags() ) if ( currentFlags != resultFlags )
{ {
core->setPartitionFlags( m_device, m_partition, newFlags() ); core->setPartitionFlags( m_device, m_partition, resultFlags );
} }
} }
else // otherwise, we delete and recreate the partition with new fs type else // otherwise, we delete and recreate the partition with new fs type
@ -196,22 +199,22 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
fsType, fsType,
m_partition->firstSector(), m_partition->firstSector(),
m_partition->lastSector(), m_partition->lastSector(),
newFlags() ); resultFlags );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true ); PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition ); core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition ); core->createPartition( m_device, newPartition );
core->setPartitionFlags( m_device, newPartition, newFlags() ); core->setPartitionFlags( m_device, newPartition, resultFlags );
} }
} }
else else
{ {
core->refreshPartition( m_device, m_partition ); if ( currentFlags != resultFlags )
if ( m_partition->activeFlags() != newFlags() )
{ {
core->setPartitionFlags( m_device, m_partition, newFlags() ); core->setPartitionFlags( m_device, m_partition, resultFlags );
} }
core->refreshPartition( m_device, m_partition );
} }
} }
} }