[partition] Chase constness, makeJob()

This commit is contained in:
Adriaan de Groot 2020-08-04 16:53:29 +02:00
parent 20b477d063
commit 23b507ae8e

View File

@ -357,9 +357,7 @@ PartitionCoreModule::createPartitionTable( Device* device, PartitionTable::Table
deviceInfo->forgetChanges(); deviceInfo->forgetChanges();
OperationHelper helper( partitionModelForDevice( device ), this ); OperationHelper helper( partitionModelForDevice( device ), this );
CreatePartitionTableJob* job = new CreatePartitionTableJob( device, type ); deviceInfo->makeJob< CreatePartitionTableJob >( type );
job->updatePreview();
deviceInfo->jobs << Calamares::job_ptr( job );
} }
} }
@ -370,15 +368,11 @@ PartitionCoreModule::createPartition( Device* device, Partition* partition, Part
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
OperationHelper helper( partitionModelForDevice( device ), this ); OperationHelper helper( partitionModelForDevice( device ), this );
CreatePartitionJob* job = new CreatePartitionJob( device, partition ); deviceInfo->makeJob< CreatePartitionJob >( partition );
job->updatePreview();
deviceInfo->jobs << Calamares::job_ptr( job );
if ( flags != KPM_PARTITION_FLAG( None ) ) if ( flags != KPM_PARTITION_FLAG( None ) )
{ {
SetPartFlagsJob* fJob = new SetPartFlagsJob( device, partition, flags ); deviceInfo->makeJob< SetPartFlagsJob >( partition, flags );
deviceInfo->jobs << Calamares::job_ptr( fJob );
PartitionInfo::setFlags( partition, flags ); PartitionInfo::setFlags( partition, flags );
} }
} }
@ -392,25 +386,18 @@ PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partitio
vgName.append( '_' ); vgName.append( '_' );
} }
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
job->updatePreview();
LvmDevice* device = new LvmDevice( vgName ); LvmDevice* device = new LvmDevice( vgName );
for ( const Partition* p : pvList ) for ( const Partition* p : pvList )
{ {
device->physicalVolumes() << p; device->physicalVolumes() << p;
} }
DeviceInfo* deviceInfo = new DeviceInfo( device ); DeviceInfo* deviceInfo = new DeviceInfo( device );
deviceInfo->partitionModel->init( device, osproberEntries() ); deviceInfo->partitionModel->init( device, osproberEntries() );
m_deviceModel->addDevice( device ); m_deviceModel->addDevice( device );
m_deviceInfos << deviceInfo; m_deviceInfos << deviceInfo;
deviceInfo->jobs << Calamares::job_ptr( job );
deviceInfo->makeJob< CreateVolumeGroupJob >( vgName, pvList, peSize );
refreshAfterModelChange(); refreshAfterModelChange();
} }
@ -419,11 +406,7 @@ PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, QVector< const Partit
{ {
auto* deviceInfo = infoForDevice( device ); auto* deviceInfo = infoForDevice( device );
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
deviceInfo->makeJob< ResizeVolumeGroupJob >( device, pvList );
ResizeVolumeGroupJob* job = new ResizeVolumeGroupJob( device, pvList );
deviceInfo->jobs << Calamares::job_ptr( job );
refreshAfterModelChange(); refreshAfterModelChange();
} }
@ -435,6 +418,7 @@ PartitionCoreModule::deactivateVolumeGroup( LvmDevice* device )
deviceInfo->isAvailable = false; deviceInfo->isAvailable = false;
// TODO: this leaks
DeactivateVolumeGroupJob* job = new DeactivateVolumeGroupJob( device ); DeactivateVolumeGroupJob* job = new DeactivateVolumeGroupJob( device );
// DeactivateVolumeGroupJob needs to be immediately called // DeactivateVolumeGroupJob needs to be immediately called
@ -448,11 +432,7 @@ PartitionCoreModule::removeVolumeGroup( LvmDevice* device )
{ {
auto* deviceInfo = infoForDevice( device ); auto* deviceInfo = infoForDevice( device );
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
deviceInfo->makeJob< RemoveVolumeGroupJob >( device );
RemoveVolumeGroupJob* job = new RemoveVolumeGroupJob( device );
deviceInfo->jobs << Calamares::job_ptr( job );
refreshAfterModelChange(); refreshAfterModelChange();
} }
@ -482,7 +462,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
} }
} }
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 // First remove matching SetPartFlagsJobs
@ -537,9 +517,8 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
++it; ++it;
} }
} }
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
job->updatePreview(); deviceInfo->makeJob< DeletePartitionJob >( partition );
jobs << Calamares::job_ptr( job );
} }
} }
@ -549,9 +528,7 @@ PartitionCoreModule::formatPartition( Device* device, Partition* partition )
auto* deviceInfo = infoForDevice( device ); auto* deviceInfo = infoForDevice( device );
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
OperationHelper helper( partitionModelForDevice( device ), this ); OperationHelper helper( partitionModelForDevice( device ), this );
deviceInfo->makeJob< FormatPartitionJob >( partition );
FormatPartitionJob* job = new FormatPartitionJob( device, partition );
deviceInfo->jobs << Calamares::job_ptr( job );
} }
void void
@ -560,10 +537,7 @@ PartitionCoreModule::resizePartition( Device* device, Partition* partition, qint
auto* deviceInfo = infoForDevice( device ); auto* deviceInfo = infoForDevice( device );
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
OperationHelper helper( partitionModelForDevice( device ), this ); OperationHelper helper( partitionModelForDevice( device ), this );
deviceInfo->makeJob< ResizePartitionJob >( partition, first, last );
ResizePartitionJob* job = new ResizePartitionJob( device, partition, first, last );
job->updatePreview();
deviceInfo->jobs << Calamares::job_ptr( job );
} }
void void
@ -572,9 +546,7 @@ PartitionCoreModule::setPartitionFlags( Device* device, Partition* partition, Pa
auto* deviceInfo = infoForDevice( device ); auto* deviceInfo = infoForDevice( device );
Q_ASSERT( deviceInfo ); Q_ASSERT( deviceInfo );
OperationHelper( partitionModelForDevice( device ), this ); OperationHelper( partitionModelForDevice( device ), this );
deviceInfo->makeJob< SetPartFlagsJob >( partition, flags );
SetPartFlagsJob* job = new SetPartFlagsJob( device, partition, flags );
deviceInfo->jobs << Calamares::job_ptr( job );
PartitionInfo::setFlags( partition, flags ); PartitionInfo::setFlags( partition, flags );
} }
@ -607,7 +579,7 @@ PartitionCoreModule::jobs() const
for ( auto info : m_deviceInfos ) for ( auto info : m_deviceInfos )
{ {
lst << info->jobs; lst << info->jobs();
devices << info->device.data(); devices << info->device.data();
} }
lst << Calamares::job_ptr( new FillGlobalStorageJob( devices, m_bootLoaderInstallPath ) ); lst << Calamares::job_ptr( new FillGlobalStorageJob( devices, m_bootLoaderInstallPath ) );
@ -661,7 +633,7 @@ PartitionCoreModule::dumpQueue() const
for ( auto info : m_deviceInfos ) for ( auto info : m_deviceInfos )
{ {
cDebug() << "## Device:" << info->device->name(); cDebug() << "## Device:" << info->device->name();
for ( auto job : info->jobs ) for ( const auto& job : info->jobs() )
{ {
cDebug() << "-" << job->prettyName(); cDebug() << "-" << job->prettyName();
} }
@ -801,7 +773,7 @@ PartitionCoreModule::scanForLVMPVs()
for ( DeviceInfo* d : m_deviceInfos ) for ( DeviceInfo* d : m_deviceInfos )
{ {
for ( auto job : d->jobs ) for ( const auto& job : d->jobs() )
{ {
// Including new LVM PVs // Including new LVM PVs
CreatePartitionJob* partJob = dynamic_cast< CreatePartitionJob* >( job.data() ); CreatePartitionJob* partJob = dynamic_cast< CreatePartitionJob* >( job.data() );
@ -1028,9 +1000,9 @@ PartitionCoreModule::revertAllDevices()
{ {
( *it )->isAvailable = true; ( *it )->isAvailable = true;
if ( !( *it )->jobs.empty() ) if ( !( *it )->jobs().empty() )
{ {
CreateVolumeGroupJob* vgJob = dynamic_cast< CreateVolumeGroupJob* >( ( *it )->jobs[ 0 ].data() ); CreateVolumeGroupJob* vgJob = dynamic_cast< CreateVolumeGroupJob* >( ( *it )->jobs().first().data() );
if ( vgJob ) if ( vgJob )
{ {