Merge pull request #872 from stikonas/3.1.x-stable
Use KPMcore SetPartFlags operation.
This commit is contained in:
commit
0729bdd0be
@ -23,14 +23,12 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <kpmcore/core/partition.h>
|
// KPMcore
|
||||||
#include <kpmcore/backend/corebackend.h>
|
#include <core/device.h>
|
||||||
#include <kpmcore/backend/corebackenddevice.h>
|
#include <core/partition.h>
|
||||||
#include <kpmcore/backend/corebackendmanager.h>
|
#include <fs/filesystem.h>
|
||||||
#include <kpmcore/backend/corebackendpartition.h>
|
#include <ops/setpartflagsoperation.h>
|
||||||
#include <kpmcore/backend/corebackendpartitiontable.h>
|
#include <util/report.h>
|
||||||
#include <kpmcore/core/device.h>
|
|
||||||
#include <kpmcore/util/report.h>
|
|
||||||
|
|
||||||
SetPartFlagsJob::SetPartFlagsJob( Device* device,
|
SetPartFlagsJob::SetPartFlagsJob( Device* device,
|
||||||
Partition* partition,
|
Partition* partition,
|
||||||
@ -131,76 +129,15 @@ SetPartFlagsJob::prettyStatusMessage() const
|
|||||||
Calamares::JobResult
|
Calamares::JobResult
|
||||||
SetPartFlagsJob::exec()
|
SetPartFlagsJob::exec()
|
||||||
{
|
{
|
||||||
PartitionTable::Flags oldFlags = partition()->availableFlags();
|
Report report (nullptr);
|
||||||
if ( oldFlags == m_flags )
|
SetPartFlagsOperation op(*m_device, *partition(), m_flags);
|
||||||
return Calamares::JobResult::ok();
|
op.setStatus(Operation::StatusRunning);
|
||||||
|
connect(&op, &Operation::progress, [&](int percent) { emit progress(percent / 100.0); } );
|
||||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
|
||||||
|
|
||||||
QString errorMessage = tr( "The installer failed to set flags on partition %1." )
|
QString errorMessage = tr( "The installer failed to set flags on partition %1." )
|
||||||
.arg( m_partition->partitionPath() );
|
.arg( m_partition->partitionPath() );
|
||||||
|
if (op.execute(report))
|
||||||
|
return Calamares::JobResult::ok();
|
||||||
|
|
||||||
QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) );
|
return Calamares::JobResult::error(errorMessage, report.toText());
|
||||||
if ( !backendDevice.data() )
|
|
||||||
{
|
|
||||||
return Calamares::JobResult::error(
|
|
||||||
errorMessage,
|
|
||||||
tr( "Could not open device '%1'." ).arg( m_device->deviceNode() )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QScopedPointer< CoreBackendPartitionTable > backendPartitionTable( backendDevice->openPartitionTable() );
|
|
||||||
if ( !backendPartitionTable.data() )
|
|
||||||
{
|
|
||||||
return Calamares::JobResult::error(
|
|
||||||
errorMessage,
|
|
||||||
tr( "Could not open partition table on device '%1'." ).arg( m_device->deviceNode() )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QScopedPointer< CoreBackendPartition > backendPartition(
|
|
||||||
( partition()->roles().has( PartitionRole::Extended ) )
|
|
||||||
? backendPartitionTable->getExtendedPartition()
|
|
||||||
: backendPartitionTable->getPartitionBySector( partition()->firstSector() )
|
|
||||||
);
|
|
||||||
if ( !backendPartition.data() ) {
|
|
||||||
return Calamares::JobResult::error(
|
|
||||||
errorMessage,
|
|
||||||
tr( "Could not find partition '%1'." ).arg( partition()->partitionPath() )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 count = 0;
|
|
||||||
|
|
||||||
foreach( const PartitionTable::Flag& f, PartitionTable::flagList() )
|
|
||||||
{
|
|
||||||
emit progress(++count);
|
|
||||||
|
|
||||||
const bool state = ( m_flags & f ) ? true : false;
|
|
||||||
|
|
||||||
Report report( nullptr );
|
|
||||||
if ( !backendPartition->setFlag( report, f, state ) )
|
|
||||||
{
|
|
||||||
cDebug() << QStringLiteral( "WARNING: Could not set flag %2 on "
|
|
||||||
"partition '%1'." )
|
|
||||||
.arg( partition()->partitionPath() )
|
|
||||||
.arg( PartitionTable::flagName( f ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACK: Partition (in KPMcore) declares SetPartFlagsJob as friend, but this actually
|
|
||||||
// refers to an unrelated class SetPartFlagsJob which is in KPMcore but is not
|
|
||||||
// exported.
|
|
||||||
// Obviously here we are relying on having a class in Calamares with the same
|
|
||||||
// name as a private one in KPMcore, which is awful, but it's the least evil
|
|
||||||
// way to call Partition::setFlags (KPMcore's SetPartFlagsJob needs its friend
|
|
||||||
// status for the very same reason).
|
|
||||||
m_partition->setFlags( m_flags );
|
|
||||||
|
|
||||||
backendPartitionTable->commit();
|
|
||||||
|
|
||||||
return Calamares::JobResult::ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "SetPartitionFlagsJob.moc"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user