[partition] Apply coding style

This commit is contained in:
Adriaan de Groot 2022-05-18 12:07:20 +02:00
parent 56071c4016
commit 8fea6f71ab
6 changed files with 233 additions and 237 deletions

View File

@ -20,9 +20,9 @@
#include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
#include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/fs/luks.h>
#include <kpmcore/fs/filesystem.h>
#include <kpmcore/util/externalcommand.h>
using CalamaresUtils::Partition::PartitionIterator;
@ -30,9 +30,9 @@ using CalamaresUtils::Partition::PartitionIterator;
namespace KPMHelpers
{
Partition*
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
{
Partition*
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
{
for ( auto device : devices )
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
@ -40,11 +40,11 @@ namespace KPMHelpers
return *it;
}
return nullptr;
}
}
Partition*
createNewPartition( PartitionNode* parent,
Partition*
createNewPartition( PartitionNode* parent,
const Device& device,
const PartitionRole& role,
FileSystem::Type fsType,
@ -52,7 +52,7 @@ namespace KPMHelpers
qint64 firstSector,
qint64 lastSector,
PartitionTable::Flags flags )
{
{
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector, device.logicalSize() );
fs->setLabel( fsLabel );
return new Partition( parent,
@ -67,11 +67,11 @@ namespace KPMHelpers
false /* mounted */,
flags /* activeFlags */,
KPM_PARTITION_STATE( New ) );
}
}
Partition*
createNewEncryptedPartition( PartitionNode* parent,
Partition*
createNewEncryptedPartition( PartitionNode* parent,
const Device& device,
const PartitionRole& role,
FileSystem::Type fsType,
@ -80,7 +80,7 @@ namespace KPMHelpers
qint64 lastSector,
const QString& passphrase,
PartitionTable::Flags flags )
{
{
PartitionRole::Roles newRoles = role.roles();
if ( !role.has( PartitionRole::Luks ) )
{
@ -111,12 +111,12 @@ namespace KPMHelpers
flags /* activeFlags */,
KPM_PARTITION_STATE( New ) );
return p;
}
}
Partition*
clonePartition( Device* device, Partition* partition )
{
Partition*
clonePartition( Device* device, Partition* partition )
{
FileSystem* fs = FileSystemFactory::create(
partition->fileSystem().type(), partition->firstSector(), partition->lastSector(), device->logicalSize() );
return new Partition( partition->parent(),
@ -127,12 +127,12 @@ namespace KPMHelpers
fs->lastSector(),
partition->partitionPath(),
partition->activeFlags() );
}
}
// Adapted from luks cryptOpen which always opens a dialog to ask for a passphrase
int
updateLuksDevice( Partition* partition, const QString& passphrase )
{
// Adapted from luks cryptOpen which always opens a dialog to ask for a passphrase
int
updateLuksDevice( Partition* partition, const QString& passphrase )
{
const QString deviceNode = partition->partitionPath();
cDebug() << "Update Luks device: " << deviceNode;
@ -161,7 +161,7 @@ namespace KPMHelpers
if ( luksFs->isCryptOpen() )
{
if ( !luksFs->mapperName().isEmpty())
if ( !luksFs->mapperName().isEmpty() )
{
cWarning() << Logger::SubEntry << "#4: Device already decrypted";
return 4;
@ -174,13 +174,9 @@ namespace KPMHelpers
}
ExternalCommand openCmd( QStringLiteral( "cryptsetup" ),
{ QStringLiteral( "open" ),
deviceNode,
luksFs->suggestedMapperName( deviceNode ) } );
{ QStringLiteral( "open" ), deviceNode, luksFs->suggestedMapperName( deviceNode ) } );
if ( !( openCmd.write( passphrase.toLocal8Bit() + '\n' ) &&
openCmd.start( -1 ) &&
openCmd.exitCode() == 0 ) )
if ( !( openCmd.write( passphrase.toLocal8Bit() + '\n' ) && openCmd.start( -1 ) && openCmd.exitCode() == 0 ) )
{
cWarning() << Logger::SubEntry << openCmd.exitCode() << ": cryptsetup command failed";
return openCmd.exitCode();
@ -207,11 +203,11 @@ namespace KPMHelpers
}
return 0;
}
}
Calamares::JobResult
execute( Operation& operation, const QString& failureMessage )
{
Calamares::JobResult
execute( Operation& operation, const QString& failureMessage )
{
operation.setStatus( Operation::StatusRunning );
Report report( nullptr );
@ -225,7 +221,7 @@ namespace KPMHelpers
std::for_each( l.begin(), l.end(), []( QString& s ) { CalamaresUtils::removeLeading( s, '=' ); } );
return Calamares::JobResult::error( failureMessage, l.join( '\n' ) );
}
}
} // namespace KPMHelpers

View File

@ -43,17 +43,17 @@ class PartitionRole;
namespace KPMHelpers
{
/**
/**
* Iterates on all devices and return the first partition which is associated
* with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint()
*/
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
/**
/**
* Helper function to create a new Partition object (does not create anything
* on the disk) associated with a FileSystem.
*/
Partition* createNewPartition( PartitionNode* parent,
Partition* createNewPartition( PartitionNode* parent,
const Device& device,
const PartitionRole& role,
FileSystem::Type fsType,
@ -62,7 +62,7 @@ namespace KPMHelpers
qint64 lastSector,
PartitionTable::Flags flags );
Partition* createNewEncryptedPartition( PartitionNode* parent,
Partition* createNewEncryptedPartition( PartitionNode* parent,
const Device& device,
const PartitionRole& role,
FileSystem::Type fsType,
@ -72,27 +72,27 @@ namespace KPMHelpers
const QString& passphrase,
PartitionTable::Flags flags );
Partition* clonePartition( Device* device, Partition* partition );
Partition* clonePartition( Device* device, Partition* partition );
int updateLuksDevice( Partition* partition, const QString& passphrase );
int updateLuksDevice( Partition* partition, const QString& passphrase );
/** @brief Return a result for an @p operation
/** @brief Return a result for an @p operation
*
* Executes the operation, and if successful, returns a success result.
* Otherwise returns an error using @p failureMessage as the primary part
* of the error, and details obtained from the operation.
*/
Calamares::JobResult execute( Operation& operation, const QString& failureMessage );
/** @brief Return a result for an @p operation
Calamares::JobResult execute( Operation& operation, const QString& failureMessage );
/** @brief Return a result for an @p operation
*
* It's acceptable to use an rvalue: the operation-running is the effect
* you're interested in, rather than keeping the temporary around.
*/
static inline Calamares::JobResult
execute( Operation&& operation, const QString& failureMessage )
{
static inline Calamares::JobResult
execute( Operation&& operation, const QString& failureMessage )
{
return execute( operation, failureMessage );
}
}
} // namespace KPMHelpers

View File

@ -467,10 +467,14 @@ ChoicePage::onActionChanged()
}
// Whole disk encryption isn't implemented for zfs so disable the option for now
if ( m_eraseFsTypesChoiceComboBox != nullptr && m_enableEncryptionWidget ) {
if ( m_eraseFsTypesChoiceComboBox->currentText() == "zfs" ) {
if ( m_eraseFsTypesChoiceComboBox != nullptr && m_enableEncryptionWidget )
{
if ( m_eraseFsTypesChoiceComboBox->currentText() == "zfs" )
{
m_encryptWidget->hide();
} else {
}
else
{
m_encryptWidget->show();
}
}

View File

@ -17,10 +17,10 @@
#include "ui_EditExistingPartitionDialog.h"
#include "core/ColorUtils.h"
#include "core/KPMHelpers.h"
#include "core/PartUtils.h"
#include "core/PartitionCoreModule.h"
#include "core/PartitionInfo.h"
#include "core/KPMHelpers.h"
#include "gui/PartitionDialogHelpers.h"
#include "gui/PartitionSizeController.h"
@ -38,9 +38,9 @@
#include <QComboBox>
#include <QDir>
#include <QPushButton>
#include <QProcess>
#include <QMessageBox>
#include <QProcess>
#include <QPushButton>
using CalamaresUtils::Partition::untranslatedFS;
using CalamaresUtils::Partition::userVisibleFS;
@ -265,8 +265,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
"or delete and create a new encrypted partition." )
.arg( m_partition->partitionPath() );
QMessageBox mb( QMessageBox::Information, message, description,
QMessageBox::Ok, this->parentWidget() );
QMessageBox mb( QMessageBox::Information, message, description, QMessageBox::Ok, this->parentWidget() );
Calamares::fixButtonLabels( &mb );
mb.exec();
}
@ -321,7 +320,6 @@ EditExistingPartitionDialog::updateMountPointPicker()
}
toggleEncryptWidget();
}
void
@ -344,10 +342,8 @@ EditExistingPartitionDialog::toggleEncryptWidget()
// and not currently formatted
// and its mount point not a standard mount point except when it's /home
QString mp = selectedMountPoint( m_ui->mountPointComboBox );
if ( !mp.isEmpty()
&& m_partition->fileSystem().type() == FileSystem::Luks
&& !m_ui->formatRadioButton->isChecked()
&& ( !standardMountPoints().contains(mp) || mp == "/home" ) )
if ( !mp.isEmpty() && m_partition->fileSystem().type() == FileSystem::Luks && !m_ui->formatRadioButton->isChecked()
&& ( !standardMountPoints().contains( mp ) || mp == "/home" ) )
{
m_ui->encryptWidget->show();
m_ui->encryptWidget->reset( false );

View File

@ -149,7 +149,7 @@ EncryptWidget::updateState()
}
Encryption newState;
if ( m_ui->m_encryptCheckBox->isChecked() || !m_ui->m_encryptCheckBox->isVisible())
if ( m_ui->m_encryptCheckBox->isChecked() || !m_ui->m_encryptCheckBox->isVisible() )
{
if ( !m_ui->m_passphraseLineEdit->text().isEmpty()
&& m_ui->m_passphraseLineEdit->text() == m_ui->m_confirmLineEdit->text() )