]> git.ipfire.org Git - people/stevee/pakfire.git/blob - src/libpakfire/transaction.c
Import libpakfire
[people/stevee/pakfire.git] / src / libpakfire / transaction.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2013 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #include <solv/transaction.h>
22
23 #include <pakfire/package.h>
24 #include <pakfire/packagelist.h>
25 #include <pakfire/step.h>
26 #include <pakfire/transaction.h>
27 #include <pakfire/types.h>
28 #include <pakfire/util.h>
29
30 PakfireTransaction pakfire_transaction_create(PakfirePool pool, Transaction* trans) {
31 PakfireTransaction transaction = pakfire_calloc(1, sizeof(*transaction));
32 transaction->pool = pool;
33
34 // Clone the transaction, so we get independent from what ever called this.
35 if (trans) {
36 transaction->transaction = transaction_create_clone(trans);
37 transaction_order(transaction->transaction, 0);
38 } else {
39 transaction->transaction = transaction_create(trans->pool);
40 }
41
42 return transaction;
43 }
44
45 void pakfire_transaction_free(PakfireTransaction transaction) {
46 transaction_free(transaction->transaction);
47 pakfire_free(transaction);
48 }
49
50 int pakfire_transaction_count(PakfireTransaction transaction) {
51 return transaction->transaction->steps.count;
52 }
53
54 int pakfire_transaction_installsizechange(PakfireTransaction transaction) {
55 int sizechange = transaction_calc_installsizechange(transaction->transaction);
56 printf("SIZECHANGE %d\n", sizechange);
57
58 // Convert from kbytes to bytes
59 return sizechange * 1024;
60 }
61
62 PakfireStep pakfire_transaction_get_step(PakfireTransaction transaction, int index) {
63 Transaction* trans = transaction->transaction;
64
65 if (index >= trans->steps.count)
66 return NULL;
67
68 return pakfire_step_create(transaction, trans->steps.elements[index]);
69 }
70
71 PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, int type) {
72 PakfirePool pool = pakfire_transaction_pool(transaction);
73 Transaction* trans = transaction->transaction;
74
75 PakfirePackageList packagelist = pakfire_packagelist_create();
76
77 for (int i = 0; i < trans->steps.count; i++) {
78 Id p = trans->steps.elements[i];
79 Id t = transaction_type(trans, p,
80 SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_CHANGE_IS_REINSTALL);
81
82 if (t == type) {
83 PakfirePackage package = pakfire_package_create(pool, p);
84 pakfire_packagelist_push(packagelist, package);
85 }
86 }
87
88 return packagelist;
89 }