Lock the whole replace operation in a mutex.
This commit is contained in:
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 ]
|
||||||
{
|
{
|
||||||
// We can't use the PartitionPtrRole because we need to make changes to the
|
watcher->deleteLater();
|
||||||
// main DeviceModel, not the immutable copy.
|
} );
|
||||||
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
|
|
||||||
Partition* partition = KPMHelpers::findPartitionByPath( { selectedDevice() },
|
auto doReplace = [ this, current, dev = selectedDevice() ]
|
||||||
partPath );
|
{
|
||||||
if ( partition )
|
QMutexLocker( &( this->m_coreMutex ) );
|
||||||
PartitionActions::doReplacePartition( m_core,
|
|
||||||
selectedDevice(),
|
|
||||||
partition );
|
|
||||||
PartitionModel* m = qobject_cast< PartitionModel* >( m_afterPartitionBarsView->model() );
|
|
||||||
if ( m )
|
|
||||||
m->update();
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( m_core->isDirty() )
|
if ( m_core->isDirty() )
|
||||||
{
|
{
|
||||||
m_core->asyncRevertDevice( selectedDevice(), doReplace );
|
m_core->revertDevice( dev );
|
||||||
}
|
}
|
||||||
else
|
// We can't use the PartitionPtrRole because we need to make changes to the
|
||||||
doReplace();
|
// main DeviceModel, not the immutable copy.
|
||||||
|
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
|
||||||
|
Partition* partition = KPMHelpers::findPartitionByPath( { dev },
|
||||||
|
partPath );
|
||||||
|
if ( partition )
|
||||||
|
PartitionActions::doReplacePartition( m_core,
|
||||||
|
dev,
|
||||||
|
partition );
|
||||||
|
};
|
||||||
|
|
||||||
|
QFuture< void > future = QtConcurrent::run( doReplace );
|
||||||
|
watcher->setFuture( future );
|
||||||
} );
|
} );
|
||||||
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…
Reference in New Issue
Block a user