mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-29 18:35:37 -04:00
[partition] Apply coding style to core/ subdir
Because this is a giant code change, with no functional effect, I've been saving this until the end of the kpmcore-manager branch.
This commit is contained in:
parent
2bc296b468
commit
7f295d9565
23 changed files with 690 additions and 484 deletions
|
@ -52,17 +52,25 @@ QString
|
|||
convenienceName( const Partition* const candidate )
|
||||
{
|
||||
if ( !candidate->mountPoint().isEmpty() )
|
||||
{
|
||||
return candidate->mountPoint();
|
||||
}
|
||||
if ( !candidate->partitionPath().isEmpty() )
|
||||
{
|
||||
return candidate->partitionPath();
|
||||
}
|
||||
if ( !candidate->devicePath().isEmpty() )
|
||||
{
|
||||
return candidate->devicePath();
|
||||
}
|
||||
if ( !candidate->deviceNode().isEmpty() )
|
||||
{
|
||||
return candidate->devicePath();
|
||||
}
|
||||
|
||||
QString p;
|
||||
QTextStream s( &p );
|
||||
s << (void *)candidate;
|
||||
s << (void*)candidate;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -111,9 +119,9 @@ canBeReplaced( Partition* candidate )
|
|||
Logger::CDebug deb;
|
||||
deb << Logger::SubEntry << "NO, insufficient storage";
|
||||
deb << Logger::Continuation << "Required storage B:" << requiredStorageB
|
||||
<< QString( "(%1GiB)" ).arg( requiredStorageGiB );
|
||||
<< QString( "(%1GiB)" ).arg( requiredStorageGiB );
|
||||
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
||||
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) );
|
||||
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -129,11 +137,10 @@ canBeResized( Partition* candidate )
|
|||
}
|
||||
|
||||
cDebug() << "Checking if" << convenienceName( candidate ) << "can be resized.";
|
||||
if ( !candidate->fileSystem().supportGrow() ||
|
||||
!candidate->fileSystem().supportShrink() )
|
||||
if ( !candidate->fileSystem().supportGrow() || !candidate->fileSystem().supportShrink() )
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name()
|
||||
<< "does not support resize.";
|
||||
<< "does not support resize.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -160,8 +167,8 @@ canBeResized( Partition* candidate )
|
|||
|
||||
if ( table->numPrimaries() >= table->maxPrimaries() )
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "NO, partition table already has"
|
||||
<< table->maxPrimaries() << "primary partitions.";
|
||||
cDebug() << Logger::SubEntry << "NO, partition table already has" << table->maxPrimaries()
|
||||
<< "primary partitions.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -189,11 +196,11 @@ canBeResized( Partition* candidate )
|
|||
Logger::CDebug deb;
|
||||
deb << Logger::SubEntry << "NO, insufficient storage";
|
||||
deb << Logger::Continuation << "Required storage B:" << advisedStorageB
|
||||
<< QString( "(%1GiB)" ).arg( advisedStorageGiB );
|
||||
<< QString( "(%1GiB)" ).arg( advisedStorageGiB );
|
||||
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
||||
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) )
|
||||
<< "for" << convenienceName( candidate ) << "length:" << candidate->length()
|
||||
<< "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name();
|
||||
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) << "for"
|
||||
<< convenienceName( candidate ) << "length:" << candidate->length()
|
||||
<< "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -227,27 +234,28 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath )
|
|||
static FstabEntryList
|
||||
lookForFstabEntries( const QString& partitionPath )
|
||||
{
|
||||
QStringList mountOptions{ "ro" };
|
||||
QStringList mountOptions { "ro" };
|
||||
|
||||
auto r = CalamaresUtils::System::runCommand(
|
||||
CalamaresUtils::System::RunLocation::RunInHost,
|
||||
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath }
|
||||
);
|
||||
auto r = CalamaresUtils::System::runCommand( CalamaresUtils::System::RunLocation::RunInHost,
|
||||
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath } );
|
||||
if ( r.getExitCode() )
|
||||
{
|
||||
cWarning() << "blkid on" << partitionPath << "failed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
QString fstype = r.getOutput().trimmed();
|
||||
if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) )
|
||||
{
|
||||
mountOptions.append( "noload" );
|
||||
}
|
||||
}
|
||||
|
||||
cDebug() << "Checking device" << partitionPath
|
||||
<< "for fstab (fs=" << r.getOutput() << ')';
|
||||
cDebug() << "Checking device" << partitionPath << "for fstab (fs=" << r.getOutput() << ')';
|
||||
|
||||
FstabEntryList fstabEntries;
|
||||
|
||||
CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join(',') );
|
||||
CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join( ',' ) );
|
||||
if ( mount.isValid() )
|
||||
{
|
||||
QFile fstabFile( mount.path() + "/etc/fstab" );
|
||||
|
@ -256,32 +264,39 @@ lookForFstabEntries( const QString& partitionPath )
|
|||
|
||||
if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() )
|
||||
.split( '\n' );
|
||||
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() ).split( '\n' );
|
||||
|
||||
for ( const QString& rawLine : fstabLines )
|
||||
{
|
||||
fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) );
|
||||
}
|
||||
fstabFile.close();
|
||||
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "lines.";
|
||||
std::remove_if( fstabEntries.begin(), fstabEntries.end(), [](const FstabEntry& x) { return !x.isValid(); } );
|
||||
std::remove_if(
|
||||
fstabEntries.begin(), fstabEntries.end(), []( const FstabEntry& x ) { return !x.isValid(); } );
|
||||
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "fstab entries.";
|
||||
}
|
||||
else
|
||||
{
|
||||
cWarning() << "Could not read fstab from mounted fs";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cWarning() << "Could not mount existing fs";
|
||||
}
|
||||
|
||||
return fstabEntries;
|
||||
}
|
||||
|
||||
|
||||
static QString
|
||||
findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
||||
const QString& mountPoint )
|
||||
findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& mountPoint )
|
||||
{
|
||||
if ( fstab.isEmpty() )
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
for ( const FstabEntry& entry : fstab )
|
||||
{
|
||||
|
@ -290,7 +305,7 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
|||
QProcess readlink;
|
||||
QString partPath;
|
||||
|
||||
if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node
|
||||
if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node
|
||||
{
|
||||
partPath = entry.partitionNode;
|
||||
}
|
||||
|
@ -325,17 +340,22 @@ findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
|||
|
||||
// At this point we either have /dev/sda1, or /dev/disk/by-something/...
|
||||
|
||||
if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node
|
||||
if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node
|
||||
{
|
||||
readlink.start( "readlink", { "-en", partPath });
|
||||
readlink.start( "readlink", { "-en", partPath } );
|
||||
if ( !readlink.waitForStarted( 1000 ) )
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
if ( !readlink.waitForFinished( 1000 ) )
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
|
||||
{
|
||||
return QString();
|
||||
partPath = QString::fromLocal8Bit(
|
||||
readlink.readAllStandardOutput() ).trimmed();
|
||||
}
|
||||
partPath = QString::fromLocal8Bit( readlink.readAllStandardOutput() ).trimmed();
|
||||
}
|
||||
|
||||
return partPath;
|
||||
|
@ -364,9 +384,7 @@ runOsprober( PartitionCoreModule* core )
|
|||
}
|
||||
else
|
||||
{
|
||||
osproberOutput.append(
|
||||
QString::fromLocal8Bit(
|
||||
osprober.readAllStandardOutput() ).trimmed() );
|
||||
osproberOutput.append( QString::fromLocal8Bit( osprober.readAllStandardOutput() ).trimmed() );
|
||||
}
|
||||
|
||||
QStringList osproberCleanLines;
|
||||
|
@ -379,32 +397,37 @@ runOsprober( PartitionCoreModule* core )
|
|||
QStringList lineColumns = line.split( ':' );
|
||||
QString prettyName;
|
||||
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
||||
{
|
||||
prettyName = lineColumns.value( 1 ).simplified();
|
||||
}
|
||||
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
||||
{
|
||||
prettyName = lineColumns.value( 2 ).simplified();
|
||||
}
|
||||
|
||||
QString path = lineColumns.value( 0 ).simplified();
|
||||
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
||||
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FstabEntryList fstabEntries = lookForFstabEntries( path );
|
||||
QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" );
|
||||
|
||||
osproberEntries.append( { prettyName,
|
||||
path,
|
||||
QString(),
|
||||
canBeResized( core, path ),
|
||||
lineColumns,
|
||||
fstabEntries,
|
||||
homePath } );
|
||||
osproberEntries.append(
|
||||
{ prettyName, path, QString(), canBeResized( core, path ), lineColumns, fstabEntries, homePath } );
|
||||
osproberCleanLines.append( line );
|
||||
}
|
||||
}
|
||||
|
||||
if ( osproberCleanLines.count() > 0 )
|
||||
{
|
||||
cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines );
|
||||
}
|
||||
else
|
||||
{
|
||||
cDebug() << "os-prober gave no output.";
|
||||
}
|
||||
|
||||
Calamares::JobQueue::instance()->globalStorage()->insert( "osproberLines", osproberCleanLines );
|
||||
|
||||
|
@ -427,24 +450,28 @@ isEfiBootable( const Partition* candidate )
|
|||
|
||||
/* If bit 17 is set, old-style Esp flag, it's OK */
|
||||
if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */
|
||||
const PartitionNode* root = candidate;
|
||||
while ( root && !root->isRoot() )
|
||||
{
|
||||
root = root->parent();
|
||||
cDebug() << Logger::SubEntry << "moved towards root" << (void *)root;
|
||||
cDebug() << Logger::SubEntry << "moved towards root" << (void*)root;
|
||||
}
|
||||
|
||||
// Strange case: no root found, no partition table node?
|
||||
if ( !root )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const PartitionTable* table = dynamic_cast<const PartitionTable*>( root );
|
||||
cDebug() << Logger::SubEntry << "partition table" << (void *)table << "type" << ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
||||
return table && ( table->type() == PartitionTable::TableType::gpt ) &&
|
||||
flags.testFlag( KPM_PARTITION_FLAG(Boot) );
|
||||
const PartitionTable* table = dynamic_cast< const PartitionTable* >( root );
|
||||
cDebug() << Logger::SubEntry << "partition table" << (void*)table << "type"
|
||||
<< ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
||||
return table && ( table->type() == PartitionTable::TableType::gpt ) && flags.testFlag( KPM_PARTITION_FLAG( Boot ) );
|
||||
}
|
||||
|
||||
QString
|
||||
|
@ -452,14 +479,18 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||
{
|
||||
QStringList fsLanguage { QLatin1String( "C" ) }; // Required language list to turn off localization
|
||||
if ( fsName.isEmpty() )
|
||||
{
|
||||
fsName = QStringLiteral( "ext4" );
|
||||
}
|
||||
|
||||
FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage );
|
||||
if ( tmpType != FileSystem::Unknown )
|
||||
{
|
||||
cDebug() << "Found filesystem" << fsName;
|
||||
if ( fsType )
|
||||
{
|
||||
*fsType = tmpType;
|
||||
}
|
||||
return fsName;
|
||||
}
|
||||
|
||||
|
@ -472,7 +503,9 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||
QString fsRealName = FileSystem::nameForType( t, fsLanguage );
|
||||
cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName;
|
||||
if ( fsType )
|
||||
{
|
||||
*fsType = t;
|
||||
}
|
||||
return fsRealName;
|
||||
}
|
||||
}
|
||||
|
@ -480,8 +513,10 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||
cDebug() << "Filesystem" << fsName << "not found, using ext4";
|
||||
fsName = QStringLiteral( "ext4" );
|
||||
// fsType can be used to check whether fsName was a valid filesystem.
|
||||
if (fsType)
|
||||
if ( fsType )
|
||||
{
|
||||
*fsType = FileSystem::Unknown;
|
||||
}
|
||||
#ifdef DEBUG_FILESYSTEMS
|
||||
// This bit is for distro's debugging their settings, and shows
|
||||
// all the strings that KPMCore is matching against for FS type.
|
||||
|
@ -491,13 +526,15 @@ findFS( QString fsName, FileSystem::Type* fsType )
|
|||
const auto fstypes = FileSystem::types();
|
||||
d << "Available types (" << fstypes.count() << ')';
|
||||
for ( FileSystem::Type t : fstypes )
|
||||
d << TR( static_cast<int>( t ), FileSystem::nameForType( t, fsLanguage ) );
|
||||
{
|
||||
d << TR( static_cast< int >( t ), FileSystem::nameForType( t, fsLanguage ) );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return fsName;
|
||||
}
|
||||
|
||||
} // nmamespace PartUtils
|
||||
} // namespace PartUtils
|
||||
|
||||
/* Implementation of methods for FstabEntry, from OsproberEntry.h */
|
||||
|
||||
|
@ -512,17 +549,18 @@ FstabEntry::fromEtcFstab( const QString& rawLine )
|
|||
{
|
||||
QString line = rawLine.simplified();
|
||||
if ( line.startsWith( '#' ) )
|
||||
return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 };
|
||||
return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 };
|
||||
|
||||
QStringList splitLine = line.split( ' ' );
|
||||
if ( splitLine.length() != 6 )
|
||||
return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 };
|
||||
return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 };
|
||||
|
||||
return FstabEntry{ splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
|
||||
splitLine.at( 1 ), // mount point
|
||||
splitLine.at( 2 ), // fs type
|
||||
splitLine.at( 3 ), // options
|
||||
splitLine.at( 4 ).toInt(), //dump
|
||||
splitLine.at( 5 ).toInt() //pass
|
||||
};
|
||||
}
|
||||
return FstabEntry {
|
||||
splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
|
||||
splitLine.at( 1 ), // mount point
|
||||
splitLine.at( 2 ), // fs type
|
||||
splitLine.at( 3 ), // options
|
||||
splitLine.at( 4 ).toInt(), //dump
|
||||
splitLine.at( 5 ).toInt() //pass
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue