[partition] Including revert on creation of LVM VGs.

This commit is contained in:
Caio 2018-06-08 20:20:05 -03:00
parent f8897e0e0b
commit 0465cc4214
4 changed files with 50 additions and 7 deletions

View File

@ -139,3 +139,17 @@ DeviceModel::addDevice( Device *device )
endResetModel(); endResetModel();
} }
void
DeviceModel::removeDevice( Device *device )
{
beginResetModel();
m_devices.removeAll( device );
std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 )
{
return dev1->deviceNode() < dev2->deviceNode();
} );
endResetModel();
}

View File

@ -51,6 +51,8 @@ public:
void addDevice( Device* device ); void addDevice( Device* device );
void removeDevice( Device* device );
private: private:
QList< Device* > m_devices; QList< Device* > m_devices;
}; };

View File

@ -680,8 +680,33 @@ PartitionCoreModule::revert()
void void
PartitionCoreModule::revertAllDevices() PartitionCoreModule::revertAllDevices()
{ {
foreach ( DeviceInfo* devInfo, m_deviceInfos ) for ( auto it = m_deviceInfos.begin(); it != m_deviceInfos.end(); )
revertDevice( devInfo->device.data() ); {
// In new VGs device info, there will be always a CreateVolumeGroupJob as the first job in jobs list
if ( !( *it )->jobs.empty() )
{
CreateVolumeGroupJob* vgJob = dynamic_cast<CreateVolumeGroupJob*>( ( *it )->jobs[0].data() );
if ( vgJob )
{
vgJob->undoPreview();
( *it )->forgetChanges();
m_deviceModel->removeDevice( ( *it )->device.data() );
it = m_deviceInfos.erase( it );
scanForLVMPVs();
}
}
else
{
revertDevice( ( *it )->device.data() );
++it;
}
}
refresh(); refresh();
} }
@ -691,6 +716,7 @@ PartitionCoreModule::revertDevice( Device* dev )
{ {
QMutexLocker locker( &m_revertMutex ); QMutexLocker locker( &m_revertMutex );
DeviceInfo* devInfo = infoForDevice( dev ); DeviceInfo* devInfo = infoForDevice( dev );
if ( !devInfo ) if ( !devInfo )
return; return;
devInfo->forgetChanges(); devInfo->forgetChanges();

View File

@ -222,16 +222,17 @@ PartitionPage::onNewVolumeGroupClicked()
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 ); QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
Q_ASSERT( deviceIndex.isValid() ); Q_ASSERT( deviceIndex.isValid() );
QVariant previousDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole ); QVariant previousIndexDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole );
// Creating new VG
m_core->createVolumeGroup( vgName, selectedPVs, peSize ); m_core->createVolumeGroup( vgName, selectedPVs, peSize );
// As createVolumeGroup method call resets deviceModel, // As createVolumeGroup method call resets deviceModel,
// is needed to set the current index in deviceComboBox as the previous one // is needed to set the current index in deviceComboBox as the previous one
int previousIndex = m_ui->deviceComboBox->findData( previousDeviceData, Qt::ToolTipRole ); int previousIndex = m_ui->deviceComboBox->findData( previousIndexDeviceData, Qt::ToolTipRole );
if ( previousIndex != -1 ) m_ui->deviceComboBox->setCurrentIndex( ( previousIndex < 0 ) ? 0 : previousIndex );
m_ui->deviceComboBox->setCurrentIndex( previousIndex ); updateFromCurrentDevice();
} }
delete dlg; delete dlg;
@ -301,7 +302,7 @@ PartitionPage::onRevertClicked()
int oldIndex = m_ui->deviceComboBox->currentIndex(); int oldIndex = m_ui->deviceComboBox->currentIndex();
m_core->revertAllDevices(); m_core->revertAllDevices();
m_ui->deviceComboBox->setCurrentIndex( oldIndex ); m_ui->deviceComboBox->setCurrentIndex( ( oldIndex < 0 ) ? 0 : oldIndex );
updateFromCurrentDevice(); updateFromCurrentDevice();
} ), } ),
[ this ]{ [ this ]{