From b0e55c059a3bd1de32dfc83821b2cb9bb0dab820 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Jun 2018 10:52:12 -0400 Subject: [PATCH] [calamares] Refactor searching for branding descriptor --- src/calamares/CalamaresApplication.cpp | 86 ++++++++++++-------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 29e04cb67..ef6c37912 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -172,6 +172,27 @@ settingsFileCandidates( bool assumeBuilddir ) } +static QStringList +brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename ) +{ + QStringList brandingPaths; + if ( CalamaresUtils::isAppDataDirOverridden() ) + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); + else + { + if ( assumeBuilddir ) + { + brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); + brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ) + .absoluteFilePath( brandingFilename ); + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); + } + } + + return brandingPaths; +} + + void CalamaresApplication::initQmlPath() { @@ -250,59 +271,32 @@ CalamaresApplication::initBranding() ::exit( EXIT_FAILURE ); } - QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ) - .arg( brandingComponentName ); + QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ).arg( brandingComponentName ); + QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath); QFileInfo brandingFile; - if ( CalamaresUtils::isAppDataDirOverridden() ) + bool found = false; + + foreach ( const QString& path, brandingFileCandidatesByPriority ) { - brandingFile = QFileInfo( CalamaresUtils::appDataDir() - .absoluteFilePath( brandingDescriptorSubpath ) ); - if ( !brandingFile.exists() || !brandingFile.isReadable() ) + QFileInfo pathFi( path ); + if ( pathFi.exists() && pathFi.isReadable() ) { - cError() << "FATAL: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid branding component descriptor at" - << brandingFile.absoluteFilePath() - << "\nCowardly refusing to continue startup without branding."; - ::exit( EXIT_FAILURE ); + brandingFile = pathFi; + found = true; + break; } } - else - { - QStringList brandingFileCandidatesByPriority; - if ( isDebug() ) - { - brandingFileCandidatesByPriority.append( - QDir::currentPath() + - QDir::separator() + - "src" + - QDir::separator() + - brandingDescriptorSubpath ); - } - brandingFileCandidatesByPriority.append( QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ) - .absoluteFilePath( brandingDescriptorSubpath ) ); - brandingFileCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( brandingDescriptorSubpath ) ); - - foreach ( const QString& path, brandingFileCandidatesByPriority ) - { - QFileInfo pathFi( path ); - if ( pathFi.exists() && pathFi.isReadable() ) - { - brandingFile = pathFi; - break; - } - } - if ( !brandingFile.exists() || !brandingFile.isReadable() ) - { - cError() << "FATAL: none of the expected branding descriptor file paths (" - << brandingFileCandidatesByPriority.join( ", " ) - << ") contain a valid branding.desc file." - << "\nCowardly refusing to continue startup without branding."; - ::exit( EXIT_FAILURE ); - } + if ( !found || !brandingFile.exists() || !brandingFile.isReadable() ) + { + cError() << "Cowardly refusing to continue startup without branding." + << Logger::DebugList( brandingFileCandidatesByPriority ); + if ( CalamaresUtils::isAppDataDirOverridden() ) + cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName; + else + cError() << "FATAL: none of the expected branding descriptor file paths exist."; + ::exit( EXIT_FAILURE ); } new Calamares::Branding( brandingFile.absoluteFilePath(), this );