From b5c55c7b8aa06d667ded5a41060c1bc56686d7cd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 29 Jan 2024 17:46:09 +0000 Subject: [PATCH] dependencies: Drop the legacy logger Signed-off-by: Michael Tremer --- src/libpakfire/db.c | 2 +- src/libpakfire/dependencies.c | 34 +++++++------------ src/libpakfire/include/pakfire/dependencies.h | 8 ++--- src/libpakfire/package.c | 13 ++++--- src/libpakfire/pakfire.c | 6 ++-- src/libpakfire/parser.c | 4 +-- src/libpakfire/problem.c | 26 +++++++------- src/libpakfire/transaction.c | 2 +- 8 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index bfc2b76ff..1737a9304 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -1985,7 +1985,7 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r for (const struct dependency* deps = dependencies; deps->field; deps++) { const char* relations = (const char*)sqlite3_column_text(stmt, deps->field); if (relations) { - r = pakfire_str2deps(db->pakfire, pkg, deps->key, relations); + r = pakfire_str2deps(db->ctx, pkg, deps->key, relations); if (r) goto ERROR; } diff --git a/src/libpakfire/dependencies.c b/src/libpakfire/dependencies.c index 9064fb0f6..fd24198fb 100644 --- a/src/libpakfire/dependencies.c +++ b/src/libpakfire/dependencies.c @@ -26,9 +26,6 @@ #include #include -// Enable legacy logging -#define PAKFIRE_LEGACY_LOGGING - #include #include #include @@ -88,11 +85,7 @@ PAKFIRE_EXPORT int pakfire_static_version_compare(const char* evr1, const char* return r; } -const char* pakfire_dep2str(struct pakfire* pakfire, Id id) { - Pool* pool = pakfire_get_solv_pool(pakfire); - if (!pool) - return NULL; - +const char* pakfire_dep2str(struct pakfire_ctx* ctx, Pool* pool, Id id) { return pool_dep2str(pool, id); } @@ -168,7 +161,7 @@ static Id pakfire_parse_namespace(Pool* pool, const char* s) { /* This function parses a simple dependency like "foo = 1.2.3" */ -static Id pakfire_parse_dep(struct pakfire* pakfire, const char** s) { +static Id pakfire_parse_dep(struct pakfire_ctx* ctx, Pool* pool, const char** s) { Id id = ID_NULL; if (!s) { @@ -183,8 +176,6 @@ static Id pakfire_parse_dep(struct pakfire* pakfire, const char** s) { if (!p) return ID_NULL; - Pool* pool = pakfire_get_solv_pool(pakfire); - // Consume any leading space while (isspace(*p)) p++; @@ -248,7 +239,8 @@ static Id pakfire_parse_dep(struct pakfire* pakfire, const char** s) { /* This function parses any rich dependencies */ -static Id pakfire_parse_rich_dep(struct pakfire* pakfire, const char** dep, int flags) { +static Id pakfire_parse_rich_dep(struct pakfire_ctx* ctx, + Pool* pool, const char** dep, int flags) { const char* p = *dep; Id id; @@ -263,7 +255,7 @@ static Id pakfire_parse_rich_dep(struct pakfire* pakfire, const char** dep, int switch (*p) { // A new rich dependency case '(': - id = pakfire_parse_rich_dep(pakfire, &p, 0); + id = pakfire_parse_rich_dep(ctx, pool, &p, 0); if (!id) return id; break; @@ -274,7 +266,7 @@ static Id pakfire_parse_rich_dep(struct pakfire* pakfire, const char** dep, int // Parse a regular dependency default: - id = pakfire_parse_dep(pakfire, &p); + id = pakfire_parse_dep(ctx, pool, &p); if (!id) return id; break; @@ -307,7 +299,7 @@ static Id pakfire_parse_rich_dep(struct pakfire* pakfire, const char** dep, int return ID_NULL; // Parse the next bit - Id evr = pakfire_parse_rich_dep(pakfire, &p, flags); + Id evr = pakfire_parse_rich_dep(ctx, pool, &p, flags); // Abort if there was a problem if (!evr) @@ -316,13 +308,11 @@ static Id pakfire_parse_rich_dep(struct pakfire* pakfire, const char** dep, int // Store until where we have parsed the string *dep = p; - Pool* pool = pakfire_get_solv_pool(pakfire); - // Combine everything return pool_rel2id(pool, id, evr, flags, 1); } -Id pakfire_str2dep(struct pakfire* pakfire, const char* dep) { +Id pakfire_str2dep(struct pakfire_ctx* ctx, Pool* pool, const char* dep) { Id id = ID_NULL; // Invalid input @@ -347,20 +337,20 @@ Id pakfire_str2dep(struct pakfire* pakfire, const char* dep) { // Parse any rich dependencies if (*s == '(') - id = pakfire_parse_rich_dep(pakfire, &s, 0); + id = pakfire_parse_rich_dep(ctx, pool, &s, 0); else - id = pakfire_parse_dep(pakfire, &s); + id = pakfire_parse_dep(ctx, pool, &s); // Return nothing if we could not parse the entire string if (id && *s) { - DEBUG(pakfire, "Invalid dependency: %s\n", dep); + CTX_DEBUG(ctx, "Invalid dependency: %s\n", dep); id = ID_NULL; } return id; } -int pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg, +int pakfire_str2deps(struct pakfire_ctx* ctx, struct pakfire_package* pkg, const enum pakfire_package_key key, const char* deps) { char* p = NULL; int r = 0; diff --git a/src/libpakfire/include/pakfire/dependencies.h b/src/libpakfire/include/pakfire/dependencies.h index 8dd58c339..8e8c1b988 100644 --- a/src/libpakfire/include/pakfire/dependencies.h +++ b/src/libpakfire/include/pakfire/dependencies.h @@ -27,18 +27,18 @@ int pakfire_static_version_compare(const char* evr1, const char* evr2); #include +#include #include -#include extern const struct pakfire_dep { const enum pakfire_package_key key; const char* name; } pakfire_deps[]; -const char* pakfire_dep2str(struct pakfire* pakfire, Id id); -Id pakfire_str2dep(struct pakfire* pakfire, const char* s); +const char* pakfire_dep2str(struct pakfire_ctx* ctx, Pool* pool, Id id); +Id pakfire_str2dep(struct pakfire_ctx* ctx, Pool* pool, const char* s); -int pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg, +int pakfire_str2deps(struct pakfire_ctx* ctx, struct pakfire_package* pkg, const enum pakfire_package_key key, const char* deps); #endif /* PAKFIRE_PRIVATE */ diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index e41f0a1a6..173bb476a 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -58,6 +58,8 @@ struct pakfire_package { struct pakfire* pakfire; int nrefs; + Pool* pool; + // Reference to this package in the SOLV pool Id id; struct pakfire_repo* repo; @@ -171,6 +173,9 @@ int pakfire_package_create_from_solvable(struct pakfire_package** package, pkg->pakfire = pakfire_ref(pakfire); pkg->nrefs = 1; + // Store a reference to the pool + pkg->pool = pakfire_get_solv_pool(pkg->pakfire); + // Store the ID pkg->id = id; @@ -1336,7 +1341,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_deps(struct pakfire_package* pkg, goto ERROR; for (int i = 0; i < q.count; i++) { - dep = pakfire_dep2str(pkg->pakfire, q.elements[i]); + dep = pakfire_dep2str(pkg->ctx, pkg->pool, q.elements[i]); if (!dep) goto ERROR; @@ -1363,7 +1368,7 @@ SUCCESS: int pakfire_package_add_dep(struct pakfire_package* pkg, const enum pakfire_package_key key, const char* dep) { // Parse the dependency - Id id = pakfire_str2dep(pkg->pakfire, dep); + Id id = pakfire_str2dep(pkg->ctx, pkg->pool, dep); // Silently ignore any invalid dependencies if (!id) @@ -1413,7 +1418,7 @@ static int pakfire_package_has_rich_deps_in_deparray( goto ERROR; for (int i = 0; i < q.count; i++) { - const char* dep = pakfire_dep2str(pkg->pakfire, q.elements[i]); + const char* dep = pakfire_dep2str(pkg->ctx, pkg->pool, q.elements[i]); // Is this a rich dependency? if (dep && *dep == '(') { @@ -1465,7 +1470,7 @@ int pakfire_package_matches_dep(struct pakfire_package* pkg, return r; // Get the dependency - Id depid = pakfire_str2dep(pkg->pakfire, dep); + Id depid = pakfire_str2dep(pkg->ctx, pkg->pool, dep); if (!depid) return -1; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 2430c7897..8aab98aa1 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -235,7 +235,7 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) { struct pakfire* pakfire = (struct pakfire*)data; const char* namespace = pool_id2str(pool, ns); - const char* name = pakfire_dep2str(pakfire, id); + const char* name = pakfire_dep2str(pakfire->ctx, pool, id); CTX_DEBUG(pakfire->ctx, "Namespace callback called for %s(%s)\n", namespace, name); @@ -315,7 +315,7 @@ static int pakfire_populate_pool(struct pakfire* pakfire) { }; for (const char** package = pakfire_multiinstall_packages; *package; package++) { - Id id = pakfire_str2dep(pakfire, *package); + Id id = pakfire_str2dep(pakfire->ctx, pool, *package); if (!id) continue; @@ -1373,7 +1373,7 @@ static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what pakfire_pool_internalize(pakfire); // Translate dependency to ID - Id dep = pakfire_str2dep(pakfire, what); + Id dep = pakfire_str2dep(pakfire->ctx, pakfire->pool, what); if (!dep) { errno = EINVAL; return 1; diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index 263001b7d..e686855e8 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -1082,7 +1082,7 @@ int pakfire_parser_create_package(struct pakfire_parser* parser, if (is_source) { deps = pakfire_parser_get(parser, "build", "requires"); if (deps) { - r = pakfire_str2deps(parser->pakfire, *pkg, PAKFIRE_PKG_REQUIRES, deps); + r = pakfire_str2deps(parser->ctx, *pkg, PAKFIRE_PKG_REQUIRES, deps); if (r) goto CLEANUP; } @@ -1090,7 +1090,7 @@ int pakfire_parser_create_package(struct pakfire_parser* parser, for (const struct pakfire_dep* dep = pakfire_deps; dep->key; dep++) { deps = pakfire_parser_get(parser, namespace, dep->name); if (deps) { - r = pakfire_str2deps(parser->pakfire, *pkg, dep->key, deps); + r = pakfire_str2deps(parser->ctx, *pkg, dep->key, deps); if (r) goto CLEANUP; } diff --git a/src/libpakfire/problem.c b/src/libpakfire/problem.c index 5d696dd06..8fb63a933 100644 --- a/src/libpakfire/problem.c +++ b/src/libpakfire/problem.c @@ -91,17 +91,17 @@ static char* pakfire_problem_make_string(struct pakfire_problem* problem) { case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP: r = asprintf(&s, _("nothing provides requested %s"), - pakfire_dep2str(problem->pakfire, dep)); + pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_JOB_UNKNOWN_PACKAGE: r = asprintf(&s, _("package %s does not exist"), - pakfire_dep2str(problem->pakfire, dep)); + pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM: r = asprintf(&s, _("%s is provided by the system"), - pakfire_dep2str(problem->pakfire, dep)); + pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_RPM: @@ -123,52 +123,52 @@ static char* pakfire_problem_make_string(struct pakfire_problem* problem) { case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP: r = asprintf(&s, _("nothing provides %s needed by %s"), - pakfire_dep2str(problem->pakfire, dep), pool_solvid2str(pool, source)); + pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, source)); break; case SOLVER_RULE_RPM_SAME_NAME: r = asprintf(&s, _("cannot install both %s and %s"), - pool_solvid2str(pool, source), pool_solvid2str(pool, target)); + pool_solvid2str(pool, source), pool_solvid2str(pool, target)); break; case SOLVER_RULE_RPM_PACKAGE_CONFLICT: r = asprintf(&s, _("package %s conflicts with %s provided by %s"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep), + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, target)); break; case SOLVER_RULE_RPM_PACKAGE_OBSOLETES: r = asprintf(&s, _("package %s obsoletes %s provided by %s"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep), + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, target)); break; case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES: r = asprintf(&s, _("installed package %s obsoletes %s provided by %s"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep), + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, target)); break; case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES: r = asprintf(&s, _("package %s implicitely obsoletes %s provided by %s"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep), + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, target)); break; case SOLVER_RULE_RPM_PACKAGE_REQUIRES: r = asprintf(&s, _("package %s requires %s, but none of the providers can be installed"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep)); + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_RPM_SELF_CONFLICT: r = asprintf(&s, _("package %s conflicts with %s provided by itself"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep)); + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_YUMOBS: r = asprintf(&s, _("both package %s and %s obsolete %s"), pool_solvid2str(pool, source), pool_solvid2str(pool, target), - pakfire_dep2str(problem->pakfire, dep)); + pakfire_dep2str(problem->ctx, pool, dep)); break; case SOLVER_RULE_BLACK: @@ -178,7 +178,7 @@ static char* pakfire_problem_make_string(struct pakfire_problem* problem) { case SOLVER_RULE_PKG_CONSTRAINS: r = asprintf(&s, _("package %s has constraint %s conflicting with %s"), - pool_solvid2str(pool, source), pakfire_dep2str(problem->pakfire, dep), + pool_solvid2str(pool, source), pakfire_dep2str(problem->ctx, pool, dep), pool_solvid2str(pool, target)); break; diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index efd87e05f..ee2794703 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -765,7 +765,7 @@ static int pakfire_transaction_add_job(struct pakfire_transaction* transaction, // Did we find anything? if (jobs.count == 0) { - Id id = pakfire_str2dep(transaction->pakfire, what); + Id id = pakfire_str2dep(transaction->ctx, pool, what); if (!id) { r = -errno; goto ERROR; -- 2.47.2