From d640f17ddfde063efd7e4195bf9ca529009a8324 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 17 Feb 2024 23:49:13 +0100 Subject: [PATCH] [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. --- .../partition/core/PartitionCoreModule.cpp | 28 +++++++++++++++++++ .../partition/core/PartitionCoreModule.h | 1 + .../gui/EditExistingPartitionDialog.cpp | 3 ++ 3 files changed, 32 insertions(+) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index c362dca0e..51e99f2d2 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -166,6 +166,23 @@ struct PartitionCoreModule::DeviceInfo 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 */ template < typename Job, typename... Args > @@ -1144,6 +1161,17 @@ PartitionCoreModule::clearJobs() updateIsDirty(); } +void +PartitionCoreModule::clearJobs( Device* device, Partition* partition ) +{ + DeviceInfo* devInfo = infoForDevice( device ); + + if ( devInfo ) + { + devInfo->takeJobs( partition ); + } +} + bool PartitionCoreModule::isDirty() diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index bf5145a90..40a1916a9 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -218,6 +218,7 @@ public: void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous 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 diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 34f0dea4f..df4117dff 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -190,6 +190,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) { if ( m_ui->formatRadioButton->isChecked() ) { + core->clearJobs( m_device, m_partition ); Partition* newPartition = KPMHelpers::createNewPartition( m_partition->parent(), *m_device, m_partition->roles(), @@ -224,6 +225,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) // if the FS type is unchanged, we just format if ( m_partition->fileSystem().type() == fsType ) { + core->clearJobs( m_device, m_partition ); core->formatPartition( m_device, m_partition ); if ( currentFlags != resultFlags ) { @@ -234,6 +236,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) } 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(), *m_device, m_partition->roles(),