1.1 --- a/librazor/transaction.c Sat Aug 23 16:28:31 2014 +0100
1.2 +++ b/librazor/transaction.c Thu Oct 09 17:27:41 2014 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 * Copyright (C) 2008 Red Hat, Inc
1.7 - * Copyright (C) 2009, 2011, 2012 J. Ali Harlow <ali@juiblex.co.uk>
1.8 + * Copyright (C) 2009, 2011, 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -778,40 +778,40 @@
1.13 }
1.14
1.15 static void
1.16 -describe_unsatisfied(struct razor_set *set, struct razor_property *rp)
1.17 +describe_unsatisfied(struct razor_set *set, struct razor_property *rp,
1.18 + razor_unsatisfied_callback_t callback, void *data)
1.19 {
1.20 struct razor_package_iterator pi;
1.21 struct razor_package *pkg;
1.22 const char *name, *version, *arch, *pool;
1.23 + const char *requirement;
1.24 + char *s = NULL;
1.25
1.26 pool = set->string_pool.data;
1.27 - if (pool[rp->version] == '\0') {
1.28 - razor_package_iterator_init_for_property(&pi, set, rp);
1.29 - while (razor_package_iterator_next(&pi, &pkg,
1.30 - RAZOR_DETAIL_NAME, &name,
1.31 - RAZOR_DETAIL_VERSION, &version,
1.32 - RAZOR_DETAIL_ARCH, &arch,
1.33 - RAZOR_DETAIL_LAST))
1.34 - fprintf(stderr, "%s is needed by %s-%s.%s\n",
1.35 - &pool[rp->name],
1.36 - name, version, arch);
1.37 - } else {
1.38 - razor_package_iterator_init_for_property(&pi, set, rp);
1.39 - while (razor_package_iterator_next(&pi, &pkg,
1.40 - RAZOR_DETAIL_NAME, &name,
1.41 - RAZOR_DETAIL_VERSION, &version,
1.42 - RAZOR_DETAIL_ARCH, &arch,
1.43 - RAZOR_DETAIL_LAST))
1.44 - fprintf(stderr, "%s %s %s is needed by %s-%s.%s\n",
1.45 - &pool[rp->name],
1.46 - razor_property_relation_to_string(rp),
1.47 - &pool[rp->version],
1.48 - name, version, arch);
1.49 + if (pool[rp->version] == '\0')
1.50 + requirement = &pool[rp->name];
1.51 + else {
1.52 + s = razor_concat(&pool[rp->name], " ",
1.53 + razor_property_relation_to_string(rp), " ",
1.54 + &pool[rp->version], NULL);
1.55 + requirement = s;
1.56 }
1.57 +
1.58 + razor_package_iterator_init_for_property(&pi, set, rp);
1.59 + while (razor_package_iterator_next(&pi, &pkg,
1.60 + RAZOR_DETAIL_NAME, &name,
1.61 + RAZOR_DETAIL_VERSION, &version,
1.62 + RAZOR_DETAIL_ARCH, &arch,
1.63 + RAZOR_DETAIL_LAST))
1.64 + callback(requirement, pkg, name, version, arch, data);
1.65 +
1.66 + if (s)
1.67 + free(s);
1.68 }
1.69
1.70 RAZOR_EXPORT int
1.71 -razor_transaction_describe(struct razor_transaction *trans)
1.72 +razor_transaction_unsatisfied(struct razor_transaction *trans,
1.73 + razor_unsatisfied_callback_t callback, void *data)
1.74 {
1.75 struct prop_iter rpi;
1.76 struct razor_property *rp;
1.77 @@ -825,7 +825,9 @@
1.78 prop_iter_init(&rpi, &trans->system);
1.79 while (prop_iter_next(&rpi, RAZOR_PROPERTY_REQUIRES, &rp)) {
1.80 if (!(rpi.present[rp - rpi.start] & TRANS_PROPERTY_SATISFIED)) {
1.81 - describe_unsatisfied(trans->system.set, rp);
1.82 + if (callback)
1.83 + describe_unsatisfied(trans->system.set, rp,
1.84 + callback, data);
1.85 unsatisfied++;
1.86 }
1.87 }
1.88 @@ -833,7 +835,9 @@
1.89 prop_iter_init(&rpi, &trans->upstream);
1.90 while (prop_iter_next(&rpi, RAZOR_PROPERTY_REQUIRES, &rp)) {
1.91 if (!(rpi.present[rp - rpi.start] & TRANS_PROPERTY_SATISFIED)) {
1.92 - describe_unsatisfied(trans->upstream.set, rp);
1.93 + if (callback)
1.94 + describe_unsatisfied(trans->upstream.set, rp,
1.95 + callback, data);
1.96 unsatisfied++;
1.97 }
1.98 }
1.99 @@ -841,6 +845,25 @@
1.100 return unsatisfied;
1.101 }
1.102
1.103 +static void
1.104 +describe_unsatisfied_callback(const char *requirement,
1.105 + struct razor_package *package, const char *name,
1.106 + const char *version, const char *arch, void *data)
1.107 +{
1.108 + FILE *fp = data;
1.109 +
1.110 + fprintf(fp, "%s is needed by %s-%s.%s\n", requirement,
1.111 + name, version, arch);
1.112 +}
1.113 +
1.114 +RAZOR_EXPORT int
1.115 +razor_transaction_describe(struct razor_transaction *trans)
1.116 +{
1.117 + return razor_transaction_unsatisfied(trans,
1.118 + describe_unsatisfied_callback,
1.119 + stderr);
1.120 +}
1.121 +
1.122 RAZOR_EXPORT int
1.123 razor_transaction_unsatisfied_property(struct razor_transaction *trans,
1.124 const char *name,