[partition] When format is selected, clear out existing jobs

When editing a partition multiple times, do not leave
jobs from previous edits around. Apply fresh jobs each time.
This commit is contained in:
Adriaan de Groot 2024-02-17 23:49:13 +01:00
parent 2ea5a2b5d5
commit d640f17ddf
3 changed files with 32 additions and 0 deletions

View File

@ -166,6 +166,23 @@ struct PartitionCoreModule::DeviceInfo
return Calamares::job_ptr( nullptr ); return Calamares::job_ptr( nullptr );
} }
/** @brief Take the jobs of any type that apply to @p partition */
void takeJobs( Partition* partition )
{
for ( auto it = m_jobs.begin(); it != m_jobs.end(); )
{
PartitionJob* job = qobject_cast< PartitionJob* >( it->data() );
if ( job && job->partition() == partition )
{
it = m_jobs.erase( it );
}
else
{
++it;
}
}
}
/** @brief Add a job of given type to the job list /** @brief Add a job of given type to the job list
*/ */
template < typename Job, typename... Args > template < typename Job, typename... Args >
@ -1144,6 +1161,17 @@ PartitionCoreModule::clearJobs()
updateIsDirty(); updateIsDirty();
} }
void
PartitionCoreModule::clearJobs( Device* device, Partition* partition )
{
DeviceInfo* devInfo = infoForDevice( device );
if ( devInfo )
{
devInfo->takeJobs( partition );
}
}
bool bool
PartitionCoreModule::isDirty() PartitionCoreModule::isDirty()

View File

@ -218,6 +218,7 @@ public:
void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous
void clearJobs(); // only clear jobs, the Device* states are preserved void clearJobs(); // only clear jobs, the Device* states are preserved
void clearJobs( Device* device, Partition* partition ); // clears all jobs changing @p partition
bool isDirty(); // true if there are pending changes, otherwise false bool isDirty(); // true if there are pending changes, otherwise false

View File

@ -190,6 +190,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
{ {
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
{ {
core->clearJobs( m_device, m_partition );
Partition* newPartition = KPMHelpers::createNewPartition( m_partition->parent(), Partition* newPartition = KPMHelpers::createNewPartition( m_partition->parent(),
*m_device, *m_device,
m_partition->roles(), m_partition->roles(),
@ -224,6 +225,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
// if the FS type is unchanged, we just format // if the FS type is unchanged, we just format
if ( m_partition->fileSystem().type() == fsType ) if ( m_partition->fileSystem().type() == fsType )
{ {
core->clearJobs( m_device, m_partition );
core->formatPartition( m_device, m_partition ); core->formatPartition( m_device, m_partition );
if ( currentFlags != resultFlags ) if ( currentFlags != resultFlags )
{ {
@ -234,6 +236,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
} }
else // otherwise, we delete and recreate the partition with new fs type else // otherwise, we delete and recreate the partition with new fs type
{ {
core->clearJobs( m_device, m_partition );
Partition* newPartition = KPMHelpers::createNewPartition( m_partition->parent(), Partition* newPartition = KPMHelpers::createNewPartition( m_partition->parent(),
*m_device, *m_device,
m_partition->roles(), m_partition->roles(),