Lock the whole replace operation in a mutex.

main
Teo Mrnjavac 9 years ago
parent 9847b8efa9
commit 14f4335420

@ -46,6 +46,8 @@
#include <QDir> #include <QDir>
#include <QLabel> #include <QLabel>
#include <QListView> #include <QListView>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>
@ -433,28 +435,34 @@ ChoicePage::applyActionChoice( ChoicePage::Choice choice )
connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged, connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this, [ this ]( const QModelIndex& current, const QModelIndex& previous ) this, [ this ]( const QModelIndex& current, const QModelIndex& previous )
{ {
auto doReplace = [=] QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
connect( watcher, &QFutureWatcher< void >::finished,
this, [ watcher ]
{ {
watcher->deleteLater();
} );
auto doReplace = [ this, current, dev = selectedDevice() ]
{
QMutexLocker( &( this->m_coreMutex ) );
if ( m_core->isDirty() )
{
m_core->revertDevice( dev );
}
// We can't use the PartitionPtrRole because we need to make changes to the // We can't use the PartitionPtrRole because we need to make changes to the
// main DeviceModel, not the immutable copy. // main DeviceModel, not the immutable copy.
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString(); QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
Partition* partition = KPMHelpers::findPartitionByPath( { selectedDevice() }, Partition* partition = KPMHelpers::findPartitionByPath( { dev },
partPath ); partPath );
if ( partition ) if ( partition )
PartitionActions::doReplacePartition( m_core, PartitionActions::doReplacePartition( m_core,
selectedDevice(), dev,
partition ); partition );
PartitionModel* m = qobject_cast< PartitionModel* >( m_afterPartitionBarsView->model() );
if ( m )
m->update();
}; };
if ( m_core->isDirty() ) QFuture< void > future = QtConcurrent::run( doReplace );
{ watcher->setFuture( future );
m_core->asyncRevertDevice( selectedDevice(), doReplace );
}
else
doReplace();
} ); } );
break; break;
case NoChoice: case NoChoice:

@ -105,6 +105,8 @@ private:
QPointer< PartitionLabelsView > m_afterPartitionLabelsView; QPointer< PartitionLabelsView > m_afterPartitionLabelsView;
int m_lastSelectedDeviceIndex; int m_lastSelectedDeviceIndex;
QMutex m_coreMutex;
}; };
#endif // CHOICEPAGE_H #endif // CHOICEPAGE_H

Loading…
Cancel
Save