]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: steps: Make them independent from libsolv
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Jan 2021 16:35:22 +0000 (16:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 23 Jan 2021 16:35:22 +0000 (16:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/step.h
src/libpakfire/step.c
src/libpakfire/transaction.c

index a8f54ca616f3cbe435d101281858e5386529b9a8..433906735e5b6d06dd6b9c8de830eebeb38edb12 100644 (file)
 #ifndef PAKFIRE_STEP_H
 #define PAKFIRE_STEP_H
 
-#include <solv/pooltypes.h>
-
 #include <pakfire/types.h>
 
-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);
 
index 35ce79096ffdaa7647f45e82398ca21f5981e7fb..d55355384b289507a75c6ee140ff3bd3e67cbf25 100644 (file)
@@ -23,9 +23,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <solv/pooltypes.h>
-#include <solv/transaction.h>
-
 #include <pakfire/archive.h>
 #include <pakfire/constants.h>
 #include <pakfire/db.h>
@@ -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);
index 77355e92cc7a657907272e3f65ed29ce84c05532..48363580d2053255882ca533db9258c9e16b3a1b 100644 (file)
@@ -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;