Lock the whole replace operation in a mutex.
This commit is contained in:
parent
9847b8efa9
commit
14f4335420
@ -46,6 +46,8 @@
|
||||
#include <QDir>
|
||||
#include <QLabel>
|
||||
#include <QListView>
|
||||
#include <QFutureWatcher>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
|
||||
|
||||
@ -433,28 +435,34 @@ ChoicePage::applyActionChoice( ChoicePage::Choice choice )
|
||||
connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||
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
|
||||
// main DeviceModel, not the immutable copy.
|
||||
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
|
||||
Partition* partition = KPMHelpers::findPartitionByPath( { selectedDevice() },
|
||||
Partition* partition = KPMHelpers::findPartitionByPath( { dev },
|
||||
partPath );
|
||||
if ( partition )
|
||||
PartitionActions::doReplacePartition( m_core,
|
||||
selectedDevice(),
|
||||
dev,
|
||||
partition );
|
||||
PartitionModel* m = qobject_cast< PartitionModel* >( m_afterPartitionBarsView->model() );
|
||||
if ( m )
|
||||
m->update();
|
||||
};
|
||||
|
||||
if ( m_core->isDirty() )
|
||||
{
|
||||
m_core->asyncRevertDevice( selectedDevice(), doReplace );
|
||||
}
|
||||
else
|
||||
doReplace();
|
||||
QFuture< void > future = QtConcurrent::run( doReplace );
|
||||
watcher->setFuture( future );
|
||||
} );
|
||||
break;
|
||||
case NoChoice:
|
||||
|
@ -105,6 +105,8 @@ private:
|
||||
QPointer< PartitionLabelsView > m_afterPartitionLabelsView;
|
||||
|
||||
int m_lastSelectedDeviceIndex;
|
||||
|
||||
QMutex m_coreMutex;
|
||||
};
|
||||
|
||||
#endif // CHOICEPAGE_H
|
||||
|
Loading…
Reference in New Issue
Block a user