[calamares] Refactor searching for settings.conf

- Split the collection of paths off from the search itself.
This commit is contained in:
Adriaan de Groot 2018-06-29 10:15:43 -04:00
parent 3329f2ea55
commit 22ee24a5ad

View File

@ -152,6 +152,26 @@ qmlDirCandidates( bool assumeBuilddir )
} }
static QStringList
settingsFileCandidates( bool assumeBuilddir )
{
static const char settings[] = "settings.conf";
QStringList settingsPaths;
if ( CalamaresUtils::isAppDataDirOverridden() )
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
else
{
if ( assumeBuilddir )
settingsPaths << QDir::current().absoluteFilePath( settings );
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
}
return settingsPaths;
}
void void
CalamaresApplication::initQmlPath() CalamaresApplication::initQmlPath()
{ {
@ -189,51 +209,31 @@ CalamaresApplication::initQmlPath()
void void
CalamaresApplication::initSettings() CalamaresApplication::initSettings()
{ {
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() );
QFileInfo settingsFile; QFileInfo settingsFile;
if ( CalamaresUtils::isAppDataDirOverridden() ) bool found = false;
foreach ( const QString& path, settingsFileCandidatesByPriority )
{ {
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) ); QFileInfo pathFi( path );
if ( !settingsFile.exists() || !settingsFile.isReadable() ) if ( pathFi.exists() && pathFi.isReadable() )
{ {
cError() << "FATAL: explicitly configured application data directory" settingsFile = pathFi;
<< CalamaresUtils::appDataDir().absolutePath() found = true;
<< "does not contain a valid settings.conf file." break;
<< "\nCowardly refusing to continue startup without settings.";
::exit( EXIT_FAILURE );
} }
} }
else
if ( !found || !settingsFile.exists() || !settingsFile.isReadable() )
{ {
QStringList settingsFileCandidatesByPriority; cError() << "Cowardly refusing to continue startup without settings."
if ( isDebug() ) << Logger::DebugList( settingsFileCandidatesByPriority );
{ if ( CalamaresUtils::isAppDataDirOverridden() )
settingsFileCandidatesByPriority.append( cError() << "FATAL: explicitly configured application data directory is missing settings.conf";
QDir::currentPath() + else
QDir::separator() + cError() << "FATAL: none of the expected configuration file paths exist.";
"settings.conf" ); ::exit( EXIT_FAILURE );
}
settingsFileCandidatesByPriority.append( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf" );
settingsFileCandidatesByPriority.append( CalamaresUtils::appDataDir()
.absoluteFilePath( "settings.conf" ) );
foreach ( const QString& path, settingsFileCandidatesByPriority )
{
QFileInfo pathFi( path );
if ( pathFi.exists() && pathFi.isReadable() )
{
settingsFile = pathFi;
break;
}
}
if ( !settingsFile.exists() || !settingsFile.isReadable() )
{
cError() << "FATAL: none of the expected configuration file paths ("
<< settingsFileCandidatesByPriority.join( ", " )
<< ") contain a valid settings.conf file."
<< "\nCowardly refusing to continue startup without settings.";
::exit( EXIT_FAILURE );
}
} }
new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this );