Compare commits

...

3 Commits

Author SHA1 Message Date
Martchus b5ca815e4c Allow excluding packages via regex when reloading library dependencies
This recently failed because the cuda package exceeded the max. body size.
I suppose it makes generally sense to be able to exclude packages as I
don't need that package anyways.
2021-07-07 19:14:03 +02:00
Martchus d006c9ce4f Fix error handling when instantiating `std::regex` 2021-07-07 19:09:32 +02:00
Martchus 17c5f50440 Do not exit process if config values are invalid
This is not a good idea when re-reading the config after startup.
2021-07-07 19:08:47 +02:00
6 changed files with 46 additions and 7 deletions

View File

@ -104,7 +104,13 @@ BuildActionMetaInfo::BuildActionMetaInfo()
.param = "skip-dependencies",
},
},
.settings = {},
.settings = {
BuildActionSettingMetaInfo{
.name = "Package exclude regex",
.desc = "Regular expression to match package names against; matching packages will be excluded.",
.param = "pkg-exclude-regex",
},
},
.directory = false,
.sourceDb = false,
.destinationDb = true,

View File

@ -83,6 +83,7 @@ enum class CleanRepositoryFlags : BuildActionFlagType {
None,
DryRun = (1 << 0),
};
enum class ReloadLibraryDependenciesSettings : std::size_t { PackageExcludeRegex };
enum class CheckForProblemsSettings : std::size_t { IgnoreDeps, IgnoreLibDeps };
enum class PrepareBuildSettings : std::size_t { PKGBUILDsDirs };
enum class ConductBuildSettings : std::size_t { ChrootDir, ChrootDefaultUser, CCacheDir, PackageCacheDir, TestFilesDir, GpgKey };

View File

@ -9,6 +9,7 @@
#include <c++utilities/io/ansiescapecodes.h>
#include <regex>
#include <unordered_set>
using namespace std;
@ -24,10 +25,27 @@ ReloadLibraryDependencies::ReloadLibraryDependencies(ServiceSetup &setup, const
void ReloadLibraryDependencies::run()
{
// initialize
// read configuration
const auto flags = static_cast<ReloadLibraryDependenciesFlags>(m_buildAction->flags);
const auto force = flags & ReloadLibraryDependenciesFlags::ForceReload;
const auto skipDependencies = flags & ReloadLibraryDependenciesFlags::SkipDependencies;
auto &metaInfo = m_setup.building.metaInfo;
auto metaInfoLock = metaInfo.lockToRead();
const auto &typeInfo = metaInfo.typeInfoForId(BuildActionType::ReloadLibraryDependencies);
const auto packageExcludeRegexSetting = typeInfo.settings[static_cast<std::size_t>(ReloadLibraryDependenciesSettings::PackageExcludeRegex)].param;
metaInfoLock.unlock();
const auto &packageExcludeRegexValue = findSetting(packageExcludeRegexSetting);
auto packageExcludeRegex = std::regex();
if (!packageExcludeRegexValue.empty()) {
try {
packageExcludeRegex = std::regex(packageExcludeRegexValue);
} catch (const std::regex_error &e) {
reportError(argsToString("configured package exclude regex is invalid: ", e.what()));
return;
}
}
// initialize
m_remainingPackages = 0;
auto configReadLock = init(BuildActionAccess::ReadConfig, RequiredDatabases::MaybeDestination, RequiredParameters::None);
if (holds_alternative<monostate>(configReadLock)) {
@ -88,6 +106,11 @@ void ReloadLibraryDependencies::run()
if (reportAbortedIfAborted()) {
return;
}
// skip if package should be excluded
if (!packageExcludeRegexValue.empty() && std::regex_match(package->name, packageExcludeRegex)) {
m_messages.notes.emplace_back(db->name % '/' % packageName + ": matches exclude regex");
continue;
}
// skip if the package info is missing (we need the binary package's file name here)
const auto &packageInfo = package->packageInfo;
if (!packageInfo) {

View File

@ -53,7 +53,7 @@ inline void convertValue(const std::multimap<std::string, std::string> &multimap
if (error) {
cerr << Phrases::ErrorMessage << "Specified IP address \"" << value << "\" for key \"" << key << "\" is invalid" << Phrases::End
<< Phrases::SubError << error.message() << Phrases::End;
exit(-1);
return;
}
result = ip;
}
@ -70,7 +70,7 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
result = stringToNumber<unsigned short>(value);
} catch (const ConversionException &) {
cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End;
exit(-1);
return;
}
}
}
@ -93,7 +93,7 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
} catch (const regex_error &e) {
cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
cerr << e.what() << '\n';
exit(-1);
return;
}
}
}

View File

@ -273,7 +273,11 @@ void getPackages(const Params &params, ResponseHandler &&handler)
break;
case Mode::Regex:
// assume names are regexes
try {
pushPackages(params.setup.config.findPackages(std::regex(name.data(), name.size())));
} catch (const std::regex_error &e) {
throw BadRequest(argsToString("regex is invalid: ", e.what()));
}
break;
case Mode::Provides:
case Mode::Depends:

View File

@ -112,7 +112,12 @@ int main(int argc, const char *argv[])
const auto negate = negateArg.isPresent();
auto regex = std::optional<std::regex>();
if (regexArg.isPresent()) {
try {
regex = std::regex(searchTerm, std::regex::egrep);
} catch (const std::regex_error &e) {
cerr << "Specified regex is invalid: " << e.what() << endl;
exit(3);
}
}
for (const Database &db : cfg.databases) {
for (const auto &pkg : db.packages) {