Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip 2017-12-15 02:51:54 -05:00
commit e6e172db90
4 changed files with 64 additions and 103 deletions

View File

@ -21,3 +21,12 @@
PartitionJob::PartitionJob( Partition* partition )
: m_partition( partition )
{}
void PartitionJob::progress(int percent)
{
if ( percent < 0 )
percent = 0;
if ( percent > 100 )
percent = 100;
emit progress( qreal( percent / 100.0 ) );
}

View File

@ -37,6 +37,14 @@ public:
return m_partition;
}
public slots:
/** @brief Translate from KPMCore to Calamares progress.
*
* KPMCore presents progress as an integer percent from 0 .. 100,
* while Calamares uses a qreal from 0 .. 1.00 .
*/
void progress( int percent );
protected:
Partition* m_partition;
};

View File

@ -20,11 +20,15 @@
#include "jobs/ResizePartitionJob.h"
#include "utils/Units.h"
// KPMcore
#include <core/device.h>
#include <ops/resizeoperation.h>
#include <util/report.h>
using CalamaresUtils::BytesToMiB;
//- ResizePartitionJob ---------------------------------------------------------
ResizePartitionJob::ResizePartitionJob( Device* device, Partition* partition, qint64 firstSector, qint64 lastSector )
: PartitionJob( partition )
@ -51,8 +55,8 @@ ResizePartitionJob::prettyDescription() const
return tr( "Resize <strong>%2MB</strong> partition <strong>%1</strong> to "
"<strong>%3MB</strong>." )
.arg( partition()->partitionPath() )
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 )
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 );
.arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );
}
@ -62,8 +66,8 @@ ResizePartitionJob::prettyStatusMessage() const
return tr( "Resizing %2MB partition %1 to "
"%3MB." )
.arg( partition()->partitionPath() )
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 )
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 );
.arg( ( BytesToMiB( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() ) )
.arg( ( BytesToMiB( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() ) );
}
@ -76,7 +80,7 @@ ResizePartitionJob::exec()
m_partition->setLastSector( m_oldLastSector );
ResizeOperation op(*m_device, *m_partition, m_newFirstSector, m_newLastSector);
op.setStatus(Operation::StatusRunning);
connect(&op, &Operation::progress, [&](int percent) { emit progress(percent / 100.0); } );
connect(&op, &Operation::progress, this, &ResizePartitionJob::progress );
QString errorMessage = tr( "The installer failed to resize partition %1 on disk '%2'." )
.arg( m_partition->partitionPath() )

View File

@ -22,19 +22,20 @@
#include "SetPartitionFlagsJob.h"
#include "utils/Logger.h"
#include "utils/Units.h"
#include <kpmcore/core/partition.h>
#include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackenddevice.h>
#include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/backend/corebackendpartition.h>
#include <kpmcore/backend/corebackendpartitiontable.h>
#include <kpmcore/core/device.h>
#include <kpmcore/util/report.h>
// KPMcore
#include <core/device.h>
#include <core/partition.h>
#include <fs/filesystem.h>
#include <ops/setpartflagsoperation.h>
#include <util/report.h>
using CalamaresUtils::BytesToMiB;
SetPartFlagsJob::SetPartFlagsJob( Device* device,
Partition* partition,
PartitionTable::Flags flags )
Partition* partition,
PartitionTable::Flags flags )
: PartitionJob( partition )
, m_device( device )
, m_flags( flags )
@ -49,8 +50,8 @@ SetPartFlagsJob::prettyName() const
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Set flags on %1MB %2 partition." )
.arg( partition()->capacity() /1024 /1024)
.arg( partition()->fileSystem().name() );
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
return tr( "Set flags on new partition." );
}
@ -64,12 +65,12 @@ SetPartFlagsJob::prettyDescription() const
{
if ( !partition()->partitionPath().isEmpty() )
return tr( "Clear flags on partition <strong>%1</strong>." )
.arg( partition()->partitionPath() );
.arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clear flags on %1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024)
.arg( partition()->fileSystem().name() );
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
return tr( "Clear flags on new partition." );
}
@ -77,18 +78,18 @@ SetPartFlagsJob::prettyDescription() const
if ( !partition()->partitionPath().isEmpty() )
return tr( "Flag partition <strong>%1</strong> as "
"<strong>%2</strong>." )
.arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) );
.arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Flag %1MB <strong>%2</strong> partition as "
"<strong>%3</strong>." )
.arg( partition()->capacity() /1024 /1024)
.arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) );
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) );
return tr( "Flag new partition as <strong>%1</strong>." )
.arg( flagsList.join( ", " ) );
.arg( flagsList.join( ", " ) );
}
@ -100,12 +101,12 @@ SetPartFlagsJob::prettyStatusMessage() const
{
if ( !partition()->partitionPath().isEmpty() )
return tr( "Clearing flags on partition <strong>%1</strong>." )
.arg( partition()->partitionPath() );
.arg( partition()->partitionPath() );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Clearing flags on %1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024)
.arg( partition()->fileSystem().name() );
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() );
return tr( "Clearing flags on new partition." );
}
@ -113,94 +114,33 @@ SetPartFlagsJob::prettyStatusMessage() const
if ( !partition()->partitionPath().isEmpty() )
return tr( "Setting flags <strong>%2</strong> on partition "
"<strong>%1</strong>." )
.arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) );
.arg( partition()->partitionPath() )
.arg( flagsList.join( ", " ) );
if ( !partition()->fileSystem().name().isEmpty() )
return tr( "Setting flags <strong>%3</strong> on "
"%1MB <strong>%2</strong> partition." )
.arg( partition()->capacity() /1024 /1024)
.arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) );
.arg( BytesToMiB( partition()->capacity() ) )
.arg( partition()->fileSystem().name() )
.arg( flagsList.join( ", " ) );
return tr( "Setting flags <strong>%1</strong> on new partition." )
.arg( flagsList.join( ", " ) );
.arg( flagsList.join( ", " ) );
}
Calamares::JobResult
SetPartFlagsJob::exec()
{
PartitionTable::Flags oldFlags = partition()->availableFlags();
if ( oldFlags == m_flags )
return Calamares::JobResult::ok();
CoreBackend* backend = CoreBackendManager::self()->backend();
Report report ( nullptr );
SetPartFlagsOperation op( *m_device, *partition(), m_flags );
op.setStatus( Operation::StatusRunning );
connect( &op, &Operation::progress, this, &SetPartFlagsJob::progress );
QString errorMessage = tr( "The installer failed to set flags on partition %1." )
.arg( m_partition->partitionPath() );
if ( op.execute( report ) )
return Calamares::JobResult::ok();
QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) );
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();
return Calamares::JobResult::error( errorMessage, report.toText() );
}
#include "SetPartitionFlagsJob.moc"