Add razor_transaction_unsatisfied()
authorJ. Ali Harlow <ali@juiblex.co.uk>
Tue Sep 09 15:04:24 2014 +0100 (2014-09-09)
changeset 4464277359896dc
parent 445 aada48958b92
child 447 0a5e583393e1
Add razor_transaction_unsatisfied()
librazor/razor.h
librazor/transaction.c
     1.1 --- a/librazor/razor.h	Mon Sep 08 10:26:39 2014 +0100
     1.2 +++ b/librazor/razor.h	Tue Sep 09 15:04:24 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 @@ -432,6 +432,17 @@
    1.13  				     struct razor_rpm *rpm);
    1.14  void razor_transaction_update_all(struct razor_transaction *transaction);
    1.15  int razor_transaction_resolve(struct razor_transaction *trans);
    1.16 +
    1.17 +typedef void (*razor_unsatisfied_callback_t)(const char *requirement,
    1.18 +					     struct razor_package *package,
    1.19 +					     const char *name,
    1.20 +					     const char *version,
    1.21 +					     const char *arch,
    1.22 +					     void *data);
    1.23 +
    1.24 +int razor_transaction_unsatisfied(struct razor_transaction *trans,
    1.25 +				  razor_unsatisfied_callback_t callback,
    1.26 +				  void *data);
    1.27  int razor_transaction_describe(struct razor_transaction *trans);
    1.28  struct razor_set *razor_transaction_commit(struct razor_transaction *trans);
    1.29  void razor_transaction_destroy(struct razor_transaction *trans);
     2.1 --- a/librazor/transaction.c	Mon Sep 08 10:26:39 2014 +0100
     2.2 +++ b/librazor/transaction.c	Tue Sep 09 15:04:24 2014 +0100
     2.3 @@ -1,7 +1,7 @@
     2.4  /*
     2.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     2.6   * Copyright (C) 2008  Red Hat, Inc
     2.7 - * Copyright (C) 2009, 2011, 2012  J. Ali Harlow <ali@juiblex.co.uk>
     2.8 + * Copyright (C) 2009, 2011, 2012, 2014  J. Ali Harlow <ali@juiblex.co.uk>
     2.9   *
    2.10   * This program is free software; you can redistribute it and/or modify
    2.11   * it under the terms of the GNU General Public License as published by
    2.12 @@ -778,40 +778,40 @@
    2.13  }
    2.14  
    2.15  static void
    2.16 -describe_unsatisfied(struct razor_set *set, struct razor_property *rp)
    2.17 +describe_unsatisfied(struct razor_set *set, struct razor_property *rp,
    2.18 +		     razor_unsatisfied_callback_t callback, void *data)
    2.19  {
    2.20  	struct razor_package_iterator pi;
    2.21  	struct razor_package *pkg;
    2.22  	const char *name, *version, *arch, *pool;
    2.23 +	const char *requirement;
    2.24 +	char *s = NULL;
    2.25  
    2.26  	pool = set->string_pool.data;
    2.27 -	if (pool[rp->version] == '\0') {
    2.28 -		razor_package_iterator_init_for_property(&pi, set, rp);
    2.29 -		while (razor_package_iterator_next(&pi, &pkg,
    2.30 -						   RAZOR_DETAIL_NAME, &name,
    2.31 -						   RAZOR_DETAIL_VERSION, &version,
    2.32 -						   RAZOR_DETAIL_ARCH, &arch,
    2.33 -						   RAZOR_DETAIL_LAST))
    2.34 -			fprintf(stderr, "%s is needed by %s-%s.%s\n",
    2.35 -				&pool[rp->name],
    2.36 -				name, version, arch);
    2.37 -	} else {
    2.38 -		razor_package_iterator_init_for_property(&pi, set, rp);
    2.39 -		while (razor_package_iterator_next(&pi, &pkg,
    2.40 -						   RAZOR_DETAIL_NAME, &name,
    2.41 -						   RAZOR_DETAIL_VERSION, &version,
    2.42 -						   RAZOR_DETAIL_ARCH, &arch,
    2.43 -						   RAZOR_DETAIL_LAST))
    2.44 -			fprintf(stderr, "%s %s %s is needed by %s-%s.%s\n",
    2.45 -				&pool[rp->name],
    2.46 -				razor_property_relation_to_string(rp),
    2.47 -				&pool[rp->version],
    2.48 -				name, version, arch);
    2.49 +	if (pool[rp->version] == '\0')
    2.50 +		requirement = &pool[rp->name];
    2.51 +	else {
    2.52 +		s = razor_concat(&pool[rp->name], " ",
    2.53 +				 razor_property_relation_to_string(rp), " ",
    2.54 +				 &pool[rp->version], NULL);
    2.55 +		requirement = s;
    2.56  	}
    2.57 +
    2.58 +	razor_package_iterator_init_for_property(&pi, set, rp);
    2.59 +	while (razor_package_iterator_next(&pi, &pkg,
    2.60 +					   RAZOR_DETAIL_NAME, &name,
    2.61 +					   RAZOR_DETAIL_VERSION, &version,
    2.62 +					   RAZOR_DETAIL_ARCH, &arch,
    2.63 +					   RAZOR_DETAIL_LAST))
    2.64 +		callback(requirement, pkg, name, version, arch, data);
    2.65 +
    2.66 +	if (s)
    2.67 +		free(s);
    2.68  }
    2.69  
    2.70  RAZOR_EXPORT int
    2.71 -razor_transaction_describe(struct razor_transaction *trans)
    2.72 +razor_transaction_unsatisfied(struct razor_transaction *trans,
    2.73 +			      razor_unsatisfied_callback_t callback, void *data)
    2.74  {
    2.75  	struct prop_iter rpi;
    2.76  	struct razor_property *rp;
    2.77 @@ -825,7 +825,9 @@
    2.78  	prop_iter_init(&rpi, &trans->system);
    2.79  	while (prop_iter_next(&rpi, RAZOR_PROPERTY_REQUIRES, &rp)) {
    2.80  		if (!(rpi.present[rp - rpi.start] & TRANS_PROPERTY_SATISFIED)) {
    2.81 -			describe_unsatisfied(trans->system.set, rp);
    2.82 +			if (callback)
    2.83 +				describe_unsatisfied(trans->system.set, rp,
    2.84 +						     callback, data);
    2.85  		        unsatisfied++;
    2.86  		}
    2.87  	}
    2.88 @@ -833,7 +835,9 @@
    2.89  	prop_iter_init(&rpi, &trans->upstream);
    2.90  	while (prop_iter_next(&rpi, RAZOR_PROPERTY_REQUIRES, &rp)) {
    2.91  		if (!(rpi.present[rp - rpi.start] & TRANS_PROPERTY_SATISFIED)) {
    2.92 -			describe_unsatisfied(trans->upstream.set, rp);
    2.93 +			if (callback)
    2.94 +				describe_unsatisfied(trans->upstream.set, rp,
    2.95 +						     callback, data);
    2.96  			unsatisfied++;
    2.97  		}
    2.98  	}
    2.99 @@ -841,6 +845,25 @@
   2.100  	return unsatisfied;
   2.101  }
   2.102  
   2.103 +static void
   2.104 +describe_unsatisfied_callback(const char *requirement,
   2.105 +			      struct razor_package *package, const char *name,
   2.106 +			      const char *version, const char *arch, void *data)
   2.107 +{
   2.108 +	FILE *fp = data;
   2.109 +
   2.110 +	fprintf(fp, "%s is needed by %s-%s.%s\n", requirement,
   2.111 +		name, version, arch);
   2.112 +}
   2.113 +
   2.114 +RAZOR_EXPORT int
   2.115 +razor_transaction_describe(struct razor_transaction *trans)
   2.116 +{
   2.117 +	return razor_transaction_unsatisfied(trans,
   2.118 +					     describe_unsatisfied_callback,
   2.119 +					     stderr);
   2.120 +}
   2.121 +
   2.122  RAZOR_EXPORT int
   2.123  razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   2.124  				       const char *name,