From: Michael Tremer Date: Sat, 23 Jan 2021 16:35:22 +0000 (+0000) Subject: libpakfire: steps: Make them independent from libsolv X-Git-Tag: 0.9.28~1285^2~813 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a473d4311425efe10ab547bad44faf10ad4cbfb;p=pakfire.git libpakfire: steps: Make them independent from libsolv Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/step.h b/src/libpakfire/include/pakfire/step.h index a8f54ca61..433906735 100644 --- a/src/libpakfire/include/pakfire/step.h +++ b/src/libpakfire/include/pakfire/step.h @@ -21,11 +21,10 @@ #ifndef PAKFIRE_STEP_H #define PAKFIRE_STEP_H -#include - #include -PakfireStep pakfire_step_create(PakfireTransaction transaction, Id id); +PakfireStep pakfire_step_create(PakfireTransaction transaction, + pakfire_step_type_t type, PakfirePackage pkg); PakfireStep pakfire_step_ref(PakfireStep step); PakfireStep pakfire_step_unref(PakfireStep step); diff --git a/src/libpakfire/step.c b/src/libpakfire/step.c index 35ce79096..d55355384 100644 --- a/src/libpakfire/step.c +++ b/src/libpakfire/step.c @@ -23,9 +23,6 @@ #include #include -#include -#include - #include #include #include @@ -50,41 +47,6 @@ struct _PakfireStep { int nrefs; }; -static pakfire_step_type_t get_type(Transaction* transaction, Id id) { - int type = transaction_type(transaction, id, - SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_CHANGE_IS_REINSTALL); - - // Translate solver types into our own types - switch (type) { - case SOLVER_TRANSACTION_INSTALL: - case SOLVER_TRANSACTION_MULTIINSTALL: - return PAKFIRE_STEP_INSTALL; - - case SOLVER_TRANSACTION_REINSTALL: - case SOLVER_TRANSACTION_MULTIREINSTALL: - return PAKFIRE_STEP_REINSTALL; - - case SOLVER_TRANSACTION_ERASE: - return PAKFIRE_STEP_ERASE; - - case SOLVER_TRANSACTION_DOWNGRADE: - return PAKFIRE_STEP_DOWNGRADE; - - case SOLVER_TRANSACTION_UPGRADE: - return PAKFIRE_STEP_UPGRADE; - - case SOLVER_TRANSACTION_OBSOLETES: - return PAKFIRE_STEP_OBSOLETE; - - // Anything we don't care about - case SOLVER_TRANSACTION_IGNORE: - case SOLVER_TRANSACTION_REINSTALLED: - case SOLVER_TRANSACTION_DOWNGRADED: - default: - return PAKFIRE_STEP_IGNORE; - } -} - static const char* pakfire_step_script_filename(pakfire_script_type script) { switch (script) { case PAKFIRE_SCRIPT_PREIN: @@ -127,9 +89,9 @@ static const char* pakfire_step_script_filename(pakfire_script_type script) { return NULL; } -PAKFIRE_EXPORT PakfireStep pakfire_step_create(PakfireTransaction transaction, Id id) { +PAKFIRE_EXPORT PakfireStep pakfire_step_create(PakfireTransaction transaction, + pakfire_step_type_t type, PakfirePackage pkg) { Pakfire pakfire = pakfire_transaction_get_pakfire(transaction); - Transaction* t = pakfire_transaction_get_transaction(transaction); PakfireStep step = pakfire_calloc(1, sizeof(*step)); if (step) { @@ -137,10 +99,9 @@ PAKFIRE_EXPORT PakfireStep pakfire_step_create(PakfireTransaction transaction, I step->pakfire = pakfire_ref(pakfire); step->nrefs = 1; - step->type = get_type(t, id); - - // Get the package - step->package = pakfire_package_create(step->pakfire, id); + // Save everything + step->type = type; + step->package = pakfire_package_ref(pkg); } pakfire_unref(pakfire); diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 77355e92c..48363580d 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -42,6 +42,41 @@ struct _PakfireTransaction { int nrefs; }; +static pakfire_step_type_t transaction_get_step_type(Transaction* transaction, Id id) { + int type = transaction_type(transaction, id, + SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_CHANGE_IS_REINSTALL); + + // Translate solver types into our own types + switch (type) { + case SOLVER_TRANSACTION_INSTALL: + case SOLVER_TRANSACTION_MULTIINSTALL: + return PAKFIRE_STEP_INSTALL; + + case SOLVER_TRANSACTION_REINSTALL: + case SOLVER_TRANSACTION_MULTIREINSTALL: + return PAKFIRE_STEP_REINSTALL; + + case SOLVER_TRANSACTION_ERASE: + return PAKFIRE_STEP_ERASE; + + case SOLVER_TRANSACTION_DOWNGRADE: + return PAKFIRE_STEP_DOWNGRADE; + + case SOLVER_TRANSACTION_UPGRADE: + return PAKFIRE_STEP_UPGRADE; + + case SOLVER_TRANSACTION_OBSOLETES: + return PAKFIRE_STEP_OBSOLETE; + + // Anything we don't care about + case SOLVER_TRANSACTION_IGNORE: + case SOLVER_TRANSACTION_REINSTALLED: + case SOLVER_TRANSACTION_DOWNGRADED: + default: + return PAKFIRE_STEP_IGNORE; + } +} + PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_create(Pakfire pakfire, Transaction* trans) { PakfireTransaction transaction = pakfire_calloc(1, sizeof(*transaction)); if (transaction) { @@ -63,8 +98,20 @@ PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_create(Pakfire pakfire, Tr // Import all steps PakfireStep* steps = transaction->steps = pakfire_calloc(transaction->num_steps + 1, sizeof(*steps)); - for (unsigned int i = 0; i < transaction->num_steps; i++) - *steps++ = pakfire_step_create(transaction, transaction->transaction->steps.elements[i]); + for (unsigned int i = 0; i < transaction->num_steps; i++) { + Id id = transaction->transaction->steps.elements[i]; + + // Get the type + pakfire_step_type_t type = transaction_get_step_type(transaction->transaction, id); + + // Fetch the package + PakfirePackage pkg = pakfire_package_create(pakfire, id); + + // Append a new step + *steps++ = pakfire_step_create(transaction, type, pkg); + + pakfire_package_unref(pkg); + } } return transaction;