mirror of
https://github.com/parchlinux/calamares.git
synced 2025-07-03 04:15:37 -04:00
[partition] add job-removal to the support classes
This commit is contained in:
parent
17914b9cf9
commit
1f77441333
1 changed files with 59 additions and 40 deletions
|
@ -102,18 +102,21 @@ private:
|
||||||
DECLARE_HAS_METHOD( updatePreview )
|
DECLARE_HAS_METHOD( updatePreview )
|
||||||
|
|
||||||
template < typename Job >
|
template < typename Job >
|
||||||
void updatePreview( Job* job, const std::true_type& )
|
void
|
||||||
|
updatePreview( Job* job, const std::true_type& )
|
||||||
{
|
{
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Job >
|
template < typename Job >
|
||||||
void updatePreview( Job* job, const std::false_type& )
|
void
|
||||||
|
updatePreview( Job* job, const std::false_type& )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Job >
|
template < typename Job >
|
||||||
void updatePreview( Job* job )
|
void
|
||||||
|
updatePreview( Job* job )
|
||||||
{
|
{
|
||||||
updatePreview( job, has_updatePreview< Job > {} );
|
updatePreview( job, has_updatePreview< Job > {} );
|
||||||
}
|
}
|
||||||
|
@ -137,6 +140,33 @@ struct PartitionCoreModule::DeviceInfo
|
||||||
|
|
||||||
const Calamares::JobList& jobs() const { return m_jobs; }
|
const Calamares::JobList& jobs() const { return m_jobs; }
|
||||||
|
|
||||||
|
/** @brief Take the jobs of the given type that apply to @p partition
|
||||||
|
*
|
||||||
|
* Returns a job pointer to the job that has just been removed.
|
||||||
|
*/
|
||||||
|
template < typename Job >
|
||||||
|
Calamares::job_ptr takeJob( Partition* partition )
|
||||||
|
{
|
||||||
|
for ( auto it = m_jobs.begin(); it != m_jobs.end(); )
|
||||||
|
{
|
||||||
|
Job* job = qobject_cast< Job* >( it->data() );
|
||||||
|
if ( job && job->partition() == partition )
|
||||||
|
{
|
||||||
|
Calamares::job_ptr p = *it;
|
||||||
|
it = m_jobs.erase( it );
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Calamares::job_ptr( nullptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Add a job of given type to the job list
|
||||||
|
*/
|
||||||
template < typename Job, typename... Args >
|
template < typename Job, typename... Args >
|
||||||
Calamares::Job* makeJob( Args... a )
|
Calamares::Job* makeJob( Args... a )
|
||||||
{
|
{
|
||||||
|
@ -456,26 +486,20 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
||||||
const Calamares::JobList& jobs = deviceInfo->jobs();
|
const Calamares::JobList& jobs = deviceInfo->jobs();
|
||||||
if ( partition->state() == KPM_PARTITION_STATE( New ) )
|
if ( partition->state() == KPM_PARTITION_STATE( New ) )
|
||||||
{
|
{
|
||||||
// First remove matching SetPartFlagsJobs
|
// Take all the SetPartFlagsJob from the list and delete them
|
||||||
for ( auto it = jobs.begin(); it != jobs.end(); )
|
do
|
||||||
{
|
{
|
||||||
SetPartFlagsJob* job = qobject_cast< SetPartFlagsJob* >( it->data() );
|
auto job_ptr = deviceInfo->takeJob< SetPartFlagsJob >( partition );
|
||||||
if ( job && job->partition() == partition )
|
if ( job_ptr.data() )
|
||||||
{
|
{
|
||||||
it = jobs.erase( it );
|
continue;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} while ( false );
|
||||||
|
|
||||||
|
|
||||||
// Find matching CreatePartitionJob
|
// Find matching CreatePartitionJob
|
||||||
auto it = std::find_if( jobs.begin(), jobs.end(), [partition]( Calamares::job_ptr job ) {
|
auto job_ptr = deviceInfo->takeJob< CreatePartitionJob >( partition );
|
||||||
CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() );
|
if ( !job_ptr.data() )
|
||||||
return createJob && createJob->partition() == partition;
|
|
||||||
} );
|
|
||||||
if ( it == jobs.end() )
|
|
||||||
{
|
{
|
||||||
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
||||||
return;
|
return;
|
||||||
|
@ -488,7 +512,6 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
||||||
}
|
}
|
||||||
|
|
||||||
device->partitionTable()->updateUnallocated( *device );
|
device->partitionTable()->updateUnallocated( *device );
|
||||||
jobs.erase( it );
|
|
||||||
// The partition is no longer referenced by either a job or the device
|
// The partition is no longer referenced by either a job or the device
|
||||||
// partition list, so we have to delete it
|
// partition list, so we have to delete it
|
||||||
delete partition;
|
delete partition;
|
||||||
|
@ -496,18 +519,14 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove any PartitionJob on this partition
|
// Remove any PartitionJob on this partition
|
||||||
for ( auto it = jobs.begin(); it != jobs.end(); )
|
do
|
||||||
{
|
{
|
||||||
PartitionJob* job = qobject_cast< PartitionJob* >( it->data() );
|
auto job_ptr = deviceInfo->takeJob< PartitionJob >( partition );
|
||||||
if ( job && job->partition() == partition )
|
if ( job_ptr.data() )
|
||||||
{
|
{
|
||||||
it = jobs.erase( it );
|
continue;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} while ( false );
|
||||||
|
|
||||||
deviceInfo->makeJob< DeletePartitionJob >( partition );
|
deviceInfo->makeJob< DeletePartitionJob >( partition );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue