]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Use step type logic from Step objects
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 14 Jan 2018 16:48:55 +0000 (17:48 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 14 Jan 2018 16:48:55 +0000 (17:48 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/step.h
src/libpakfire/include/pakfire/transaction.h
src/libpakfire/include/pakfire/types.h
src/libpakfire/transaction.c

index 6e7611e0330846296bf63483c7ba21070a209899..70f43a7fffd2d0300e7ebef43b76a1448cdac206 100644 (file)
 
 #include <solv/pooltypes.h>
 
-#include <pakfire/transaction.h>
 #include <pakfire/types.h>
 
-typedef enum _pakfire_step_types {
-       PAKFIRE_STEP_IGNORE = 0,
-       PAKFIRE_STEP_INSTALL,
-       PAKFIRE_STEP_REINSTALL,
-       PAKFIRE_STEP_ERASE,
-       PAKFIRE_STEP_UPGRADE,
-       PAKFIRE_STEP_DOWNGRADE,
-       PAKFIRE_STEP_OBSOLETE,
-} pakfire_step_type_t;
-
 PakfireStep pakfire_step_create(PakfireTransaction transaction, Id id);
 void pakfire_step_free(PakfireStep step);
 
index 952cd40ff65c6d29176fff681a3d422b51ea09cf..25e3be6fd6cb7b1991dbb1249da9412de8662a13 100644 (file)
@@ -35,7 +35,7 @@ size_t pakfire_transaction_count(PakfireTransaction transaction);
 ssize_t pakfire_transaction_installsizechange(PakfireTransaction transaction);
 
 PakfireStep pakfire_transaction_get_step(PakfireTransaction transaction, int index);
-PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, int type);
+PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, pakfire_step_type_t type);
 
 char* pakfire_transaction_dump(PakfireTransaction transaction, size_t width);
 
@@ -43,14 +43,6 @@ int pakfire_transaction_run(PakfireTransaction transaction);
 
 #ifdef PAKFIRE_PRIVATE
 
-typedef enum _pakfire_action_types {
-       PAKFIRE_ACTION_NOOP      = 0,
-       PAKFIRE_ACTION_VERIFY    = 1 << 0,
-       PAKFIRE_ACTION_EXECUTE   = 1 << 1,
-       PAKFIRE_ACTION_PRETRANS  = 1 << 2,
-       PAKFIRE_ACTION_POSTTRANS = 1 << 3,
-} pakfire_action_type;
-
 Transaction* pakfire_transaction_get_transaction(PakfireTransaction transaction);
 
 #endif
index ca6f47a59f0a11295f77a7358c03f3e88f766390..b5d6f17dd2fca9e38eb0744d19a5f774d97aedd2 100644 (file)
@@ -66,6 +66,24 @@ enum _pakfire_comparison_types {
        PAKFIRE_GLOB      = 1 << 12,
 };
 
+typedef enum _pakfire_action_types {
+       PAKFIRE_ACTION_NOOP      = 0,
+       PAKFIRE_ACTION_VERIFY    = 1 << 0,
+       PAKFIRE_ACTION_EXECUTE   = 1 << 1,
+       PAKFIRE_ACTION_PRETRANS  = 1 << 2,
+       PAKFIRE_ACTION_POSTTRANS = 1 << 3,
+} pakfire_action_type;
+
+typedef enum _pakfire_step_types {
+       PAKFIRE_STEP_IGNORE = 0,
+       PAKFIRE_STEP_INSTALL,
+       PAKFIRE_STEP_REINSTALL,
+       PAKFIRE_STEP_ERASE,
+       PAKFIRE_STEP_UPGRADE,
+       PAKFIRE_STEP_DOWNGRADE,
+       PAKFIRE_STEP_OBSOLETE,
+} pakfire_step_type_t;
+
 #define PAKFIRE_SOLVABLE_FILEMARKER "solvable:filemarker"
 
 #endif /* PAKFIRE_TYPES_H */
index 3ab9d0b1f1b8ac5e32f9f6651701c0be47fd9266..640cd20b33295693cce6d19c5ca80bd121c8374d 100644 (file)
@@ -107,25 +107,12 @@ PAKFIRE_EXPORT ssize_t pakfire_transaction_installsizechange(PakfireTransaction
 PAKFIRE_EXPORT ssize_t pakfire_transaction_downloadsize(PakfireTransaction transaction) {
        ssize_t size = 0;
 
-       for (int i = 0; i < transaction->transaction->steps.count; i++) {
-               Id p = transaction->transaction->steps.elements[i];
-               Id t = transaction_type(transaction->transaction, p,
-                       SOLVER_TRANSACTION_SHOW_OBSOLETES |
-                       SOLVER_TRANSACTION_CHANGE_IS_REINSTALL |
-                       SOLVER_TRANSACTION_SHOW_ALL |
-                       SOLVER_TRANSACTION_SHOW_ACTIVE);
-
-               // Erasing a package does not require us to download it
-               if (t == SOLVER_TRANSACTION_ERASE)
-                       continue;
-
-               // Get the package for this step
-               PakfirePackage pkg = pakfire_package_create(transaction->pool, p);
-
-               if (!pakfire_package_is_cached(pkg))
-                       size += pakfire_package_get_downloadsize(pkg);
+       size_t steps = pakfire_transaction_count(transaction);
+       for (unsigned int i = 0; i < steps; i++) {
+               PakfireStep step = pakfire_transaction_get_step(transaction, i);
+               size += pakfire_step_get_downloadsize(step);
 
-               pakfire_package_free(pkg);
+               pakfire_step_free(step);
        }
 
        return size;
@@ -140,21 +127,21 @@ PAKFIRE_EXPORT PakfireStep pakfire_transaction_get_step(PakfireTransaction trans
        return pakfire_step_create(transaction, trans->steps.elements[index]);
 }
 
-PAKFIRE_EXPORT PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, int type) {
+PAKFIRE_EXPORT PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, pakfire_step_type_t type) {
        PakfirePackageList packagelist = pakfire_packagelist_create();
 
-       for (int i = 0; i < transaction->transaction->steps.count; i++) {
-               Id p = transaction->transaction->steps.elements[i];
-               Id t = transaction_type(transaction->transaction, p,
-                       SOLVER_TRANSACTION_SHOW_OBSOLETES |
-                       SOLVER_TRANSACTION_CHANGE_IS_REINSTALL |
-                       SOLVER_TRANSACTION_SHOW_ALL |
-                       SOLVER_TRANSACTION_SHOW_ACTIVE);
+       size_t steps = pakfire_transaction_count(transaction);
+       for (unsigned int i = 0; i < steps; i++) {
+               PakfireStep step = pakfire_transaction_get_step(transaction, i);
 
-               if (t == type) {
-                       PakfirePackage package = pakfire_package_create(transaction->pool, p);
+               if (pakfire_step_get_type(step) == type) {
+                       PakfirePackage package = pakfire_step_get_package(step);
                        pakfire_packagelist_push(packagelist, package);
+
+                       pakfire_package_free(package);
                }
+
+               pakfire_step_free(step);
        }
 
        // Sort list in place