3 Commits

Author SHA1 Message Date
Martchus b5ca815e4c Allow excluding packages via regex when reloading library dependencies 3 months ago
Martchus d006c9ce4f Fix error handling when instantiating `std::regex` 3 months ago
Martchus 17c5f50440 Do not exit process if config values are invalid 3 months ago
  1. 8
      librepomgr/buildactions/buildactionmeta.cpp
  2. 1
      librepomgr/buildactions/buildactionmeta.h
  3. 25
      librepomgr/buildactions/reloadlibrarydependencies.cpp
  4. 6
      librepomgr/helper.h
  5. 6
      librepomgr/webapi/routes.cpp
  6. 7
      pacfind/main.cpp

8
librepomgr/buildactions/buildactionmeta.cpp

@ -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,

1
librepomgr/buildactions/buildactionmeta.h

@ -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 };

25
librepomgr/buildactions/reloadlibrarydependencies.cpp

@ -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) {

6
librepomgr/helper.h

@ -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;
}
}
}

6
librepomgr/webapi/routes.cpp

@ -273,7 +273,11 @@ void getPackages(const Params &params, ResponseHandler &&handler)
break;
case Mode::Regex:
// assume names are regexes
pushPackages(params.setup.config.findPackages(std::regex(name.data(), name.size())));
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:

7
pacfind/main.cpp

@ -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()) {
regex = std::regex(searchTerm, std::regex::egrep);
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) {

Loading…
Cancel
Save