From 8fbe676280f3e51ffff6f19bdcd731f21bf0ac29 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 21 Jan 2020 19:16:10 +0100 Subject: [PATCH] [libcalamaresui] Refactor finding config file name - check for broken custom instances earlier in the loop - make free function for finding the config file name --- .../modulesystem/ModuleManager.cpp | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index 0911fedc6..206193856 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -174,6 +174,33 @@ findCustomInstance( const Settings::InstanceDescriptionList& customInstances, co return -1; } +/** @brief Returns the config file name for the fiven @p instanceKey + * + * Custom instances have custom config files, non-custom ones + * have a .conf file. Returns an empty QString on + * errors. + */ +static QString +getConfigFileName( const Settings::InstanceDescriptionList& customInstances, + const ModuleSystem::InstanceKey& instanceKey ) +{ + if ( instanceKey.isCustom() ) + { + int found = findCustomInstance( customInstances, instanceKey ); + + if ( found < 0 ) + { + // This should already have been checked and failed the module already + return QString(); + } + + return customInstances[ found ].value( "config" ); + } + else + { + return QString( "%1.conf" ).arg( instanceKey.module() ); + } +} void ModuleManager::loadModules() @@ -199,38 +226,28 @@ ModuleManager::loadModules() failedModules.append( moduleEntry ); continue; } - - - if ( !m_availableDescriptorsByModuleName.contains( instanceKey.module() ) - || m_availableDescriptorsByModuleName.value( instanceKey.module() ).isEmpty() ) - { - cError() << "Module" << instanceKey.toString() << "not found in module search paths." - << Logger::DebugList( m_paths ); - failedModules.append( instanceKey.toString() ); - continue; - } - - QString configFileName; if ( instanceKey.isCustom() ) { int found = findCustomInstance( customInstances, instanceKey ); - - if ( found > -1 ) - { - configFileName = customInstances[ found ].value( "config" ); - } - else //ought to be a custom instance, but cannot find instance entry + if ( found < 0 ) { cError() << "Custom instance" << moduleEntry << "not found in custom instances section."; failedModules.append( moduleEntry ); continue; } } - else + + if ( !m_availableDescriptorsByModuleName.contains( instanceKey.module() ) + || m_availableDescriptorsByModuleName.value( instanceKey.module() ).isEmpty() ) { - configFileName = QString( "%1.conf" ).arg( instanceKey.module() ); + cError() << "Module" << instanceKey.toString() << "not found in module search paths." + << Logger::DebugList( m_paths ); + failedModules.append( instanceKey.toString() ); + continue; } + QString configFileName = getConfigFileName( customInstances, instanceKey ); + // So now we can assume that the module entry is at least valid, // that we have a descriptor on hand (and therefore that the // module exists), and that the instance is either default or