make razor_set_update not loop forever on unsatisfiable dependencies
authorDan Winship <danw@gnome.org>
Thu Feb 21 14:58:39 2008 -0500 (2008-02-21)
changeset 1311b5338bcb7d1
parent 129 d221757574c1
child 132 f2c0c5993ff7
make razor_set_update not loop forever on unsatisfiable dependencies

this is mostly a dead-end, as to get the next test working i need to
rewrite the code as suggested in the comment above razor_set_revalidate
razor.c
test-driver.c
     1.1 --- a/razor.c	Thu Feb 21 12:09:13 2008 -0500
     1.2 +++ b/razor.c	Thu Feb 21 14:58:39 2008 -0500
     1.3 @@ -1740,7 +1740,8 @@
     1.4  	upool = upstream->string_pool.data;
     1.5  	package_pool = &upstream->package_pool;
     1.6  
     1.7 -	for (u = unsatisfied->data; u < end; u++) {
     1.8 +	u = unsatisfied->data;
     1.9 +	while (u < end) {
    1.10  		r = requires + *u;
    1.11  
    1.12  		while (p < pend &&
    1.13 @@ -1752,18 +1753,23 @@
    1.14  		while (p + 1 < pend && p->name == (p + 1)->name && p->type == (p + 1)->type)
    1.15  			p++;
    1.16  
    1.17 -		if (p == pend ||
    1.18 -		    strcmp(&pool[r->name], &upool[p->name]) != 0 ||
    1.19 -		    versioncmp(&pool[r->version], &upool[p->version]) > 0) {
    1.20 -			/* Do we need to track unsatisfiable requires
    1.21 -			 * as we go, or should we just do a
    1.22 -			 * razor_set_validate() at the end? */
    1.23 -		} else {
    1.24 +		if (p != pend &&
    1.25 +		    p->type == RAZOR_PROPERTY_PROVIDES &&
    1.26 +		    strcmp(&pool[r->name], &upool[p->name]) == 0 &&
    1.27 +		    versioncmp(&pool[r->version], &upool[p->version]) <= 0) {
    1.28  			pkg = array_add(list, sizeof *pkg);
    1.29  			/* We just pull in the first package that provides */
    1.30  			*pkg = list_first(&p->packages, package_pool)->data;
    1.31 +
    1.32 +			/* Remove this from the unsatisfied list */
    1.33 +			memmove (u, u + 1, end - (u + 1));
    1.34 +			end--;
    1.35 +		} else {
    1.36 +			/* Leave this in the unsatisfied list */
    1.37 +			u++;
    1.38  		}
    1.39 -	}	
    1.40 +	}
    1.41 +	unsatisfied->size = (void *)end - unsatisfied->data;
    1.42  }
    1.43  
    1.44  static void
    1.45 @@ -1816,12 +1822,50 @@
    1.46  	}
    1.47  }
    1.48  
    1.49 +/* FIXME: this is all wrong anyway; we should recompute the new_unsatisfied
    1.50 + * set as we add and remove packages...
    1.51 + */
    1.52 +static void
    1.53 +razor_set_revalidate(struct razor_set *orig_set,
    1.54 +		     struct array *orig_unsatisfied,
    1.55 +		     struct razor_set *new_set,
    1.56 +		     struct array *new_unsatisfied)
    1.57 +{
    1.58 +	uint32_t *nu, *nuend, *ou, *ouend;
    1.59 +	struct razor_property *new_props, *orig_props;
    1.60 +	char *new_pool, *orig_pool;
    1.61 +
    1.62 +	razor_set_validate(new_set, new_unsatisfied);
    1.63 +
    1.64 +	ouend = orig_unsatisfied->data + orig_unsatisfied->size;
    1.65 +	nuend = new_unsatisfied->data + new_unsatisfied->size;
    1.66 +	new_props = new_set->properties.data;
    1.67 +	orig_props = orig_set->properties.data;
    1.68 +	new_pool = new_set->string_pool.data;
    1.69 +	orig_pool = orig_set->string_pool.data;
    1.70 +
    1.71 +	for (nu = new_unsatisfied->data; nu < nuend; nu++) {
    1.72 +		for (ou = orig_unsatisfied->data; ou < ouend; ou++) {
    1.73 +			if (!strcmp (&new_pool[new_props[*nu].name],
    1.74 +				     &orig_pool[orig_props[*ou].name]) &&
    1.75 +			    new_props[*nu].relation == orig_props[*ou].relation &&
    1.76 +			    !strcmp (&new_pool[new_props[*nu].version],
    1.77 +				     &orig_pool[orig_props[*ou].version])) {
    1.78 +				*(nu--) = *(--nuend);
    1.79 +				break;
    1.80 +			}
    1.81 +		}
    1.82 +	}
    1.83 +
    1.84 +	new_unsatisfied->size = (void *)nuend - new_unsatisfied->data;
    1.85 +}
    1.86 +
    1.87  struct razor_set *
    1.88  razor_set_update(struct razor_set *set, struct razor_set *upstream,
    1.89  		 int count, const char **packages)
    1.90  {
    1.91  	struct razor_set *new;
    1.92 -	struct array list, unsatisfied;
    1.93 +	struct array list, unsatisfied_before, unsatisfied;
    1.94  
    1.95  	array_init(&list);
    1.96  	if (count > 0)
    1.97 @@ -1829,20 +1873,35 @@
    1.98  	else
    1.99  		find_all_packages(set, upstream, &list);
   1.100  
   1.101 +	array_init(&unsatisfied_before);
   1.102 +	razor_set_validate(set, &unsatisfied_before);
   1.103 +
   1.104  	while (list.size > 0) {
   1.105  		new = razor_set_add(set, upstream, &list);
   1.106  		array_release(&list);
   1.107 +
   1.108 +		array_init(&unsatisfied);
   1.109 +		razor_set_revalidate(set, &unsatisfied_before,
   1.110 +				     new, &unsatisfied);
   1.111 +
   1.112 +		array_init(&list);
   1.113 +		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   1.114 +
   1.115 +		if (unsatisfied.size) {
   1.116 +			/* FIXME: need to return this list */
   1.117 +			array_release(&unsatisfied);
   1.118 +			razor_set_destroy(new);
   1.119 +			razor_set_destroy(set);
   1.120 +			set = NULL;
   1.121 +			break;
   1.122 +		}
   1.123 +
   1.124  		razor_set_destroy(set);
   1.125  		set = new;
   1.126 -
   1.127 -		array_init(&unsatisfied);
   1.128 -		razor_set_validate(new, &unsatisfied);
   1.129 -		array_init(&list);
   1.130 -		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   1.131 -		array_release(&unsatisfied);
   1.132  	}
   1.133  
   1.134  	array_release(&list);
   1.135 +	array_release(&unsatisfied_before);
   1.136  
   1.137  	return set;
   1.138  }
   1.139 @@ -1856,9 +1915,6 @@
   1.140  	struct razor_package *pkgs;
   1.141  	int pkg_count, remove_count, p, r;
   1.142  	struct array unsatisfied_before;
   1.143 -	uint32_t *u, *uend, *ub, *ubend;
   1.144 -	struct razor_property *props, *propsb;
   1.145 -	char *pool, *poolb;
   1.146  
   1.147  	array_init(&unsatisfied_before);
   1.148  	razor_set_validate(set, &unsatisfied_before);
   1.149 @@ -1883,29 +1939,10 @@
   1.150  
   1.151  	new = razor_merger_finish(merger);
   1.152  
   1.153 -	razor_set_validate(new, unsatisfied);
   1.154 +	razor_set_revalidate(set, &unsatisfied_before,
   1.155 +			     new, unsatisfied);
   1.156 +	array_release(&unsatisfied_before);
   1.157  
   1.158 -	ubend = unsatisfied_before.data + unsatisfied_before.size;
   1.159 -	uend = unsatisfied->data + unsatisfied->size;
   1.160 -	props = new->properties.data;
   1.161 -	propsb = set->properties.data;
   1.162 -	pool = new->string_pool.data;
   1.163 -	poolb = set->string_pool.data;
   1.164 -
   1.165 -	for (u = unsatisfied->data; u < uend; u++) {
   1.166 -		for (ub = unsatisfied_before.data; ub < ubend; ub++) {
   1.167 -			if (!strcmp (&pool[props[*u].name],
   1.168 -				     &poolb[propsb[*ub].name]) &&
   1.169 -			    props[*u].relation == propsb[*ub].relation &&
   1.170 -			    !strcmp (&pool[props[*u].version],
   1.171 -				     &poolb[propsb[*ub].version])) {
   1.172 -				*(u--) = *(--uend);
   1.173 -				break;
   1.174 -			}
   1.175 -		}
   1.176 -	}
   1.177 -
   1.178 -	unsatisfied->size = (void *)uend - unsatisfied->data;
   1.179  	return new;
   1.180  }
   1.181  
     2.1 --- a/test-driver.c	Thu Feb 21 12:09:13 2008 -0500
     2.2 +++ b/test-driver.c	Thu Feb 21 14:58:39 2008 -0500
     2.3 @@ -60,6 +60,7 @@
     2.4  	int n_install_pkgs, n_remove_pkgs;
     2.5  
     2.6  	int in_result, result_errors;
     2.7 +	int in_unsatisfiable;
     2.8  };
     2.9  
    2.10  static void
    2.11 @@ -181,6 +182,9 @@
    2.12  	const char *name = NULL, *rel_str = NULL, *version = NULL;
    2.13  	enum razor_version_relation rel;
    2.14  
    2.15 +	if (ctx->in_unsatisfiable)
    2.16 +		return;
    2.17 +
    2.18  	get_atts(atts, "name", &name, "rel", &rel_str, "version", &version, NULL);
    2.19  	if (name == NULL) {
    2.20  		fprintf(stderr, "  no name specified for property\n");
    2.21 @@ -209,13 +213,17 @@
    2.22  static void
    2.23  end_transaction(struct test_context *ctx)
    2.24  {
    2.25 -	ctx->system_set = razor_set_update(ctx->system_set,
    2.26 -					   ctx->repo_set,
    2.27 -					   ctx->n_install_pkgs,
    2.28 -					   (const char **)ctx->install_pkgs);
    2.29 -	ctx->system_set = razor_set_remove(ctx->system_set,
    2.30 -					   ctx->n_remove_pkgs,
    2.31 -					   (const char **)ctx->remove_pkgs);
    2.32 +	if (ctx->n_install_pkgs) {
    2.33 +		ctx->system_set = razor_set_update(ctx->system_set,
    2.34 +						   ctx->repo_set,
    2.35 +						   ctx->n_install_pkgs,
    2.36 +						   (const char **)ctx->install_pkgs);
    2.37 +	}
    2.38 +	if (ctx->n_remove_pkgs && ctx->system_set) {
    2.39 +		ctx->system_set = razor_set_remove(ctx->system_set,
    2.40 +						   ctx->n_remove_pkgs,
    2.41 +						   (const char **)ctx->remove_pkgs);
    2.42 +	}
    2.43  
    2.44  	while (ctx->n_install_pkgs--)
    2.45  		free(ctx->install_pkgs[ctx->n_install_pkgs]);
    2.46 @@ -279,27 +287,34 @@
    2.47  {
    2.48  	ctx->in_result = 0;
    2.49  
    2.50 -	if (ctx->system_set && ctx->result_set) {
    2.51 +	if (ctx->result_set) {
    2.52 +		if (!ctx->system_set)
    2.53 +			ctx->system_set = razor_set_create();
    2.54  		ctx->result_errors = 0;
    2.55  		razor_set_diff(ctx->system_set, ctx->result_set,
    2.56  			       diff_callback, ctx);
    2.57  		if (ctx->result_errors)
    2.58  			exit(1);
    2.59  	}
    2.60 -
    2.61  }
    2.62  
    2.63  static void
    2.64 -start_unsatisfied(struct test_context *ctx, const char **atts)
    2.65 +start_unsatisfiable(struct test_context *ctx, const char **atts)
    2.66  {
    2.67 +	if (ctx->system_set) {
    2.68 +		fprintf(stderr, "Expected to fail, but didn't\n");
    2.69 +		exit(1);
    2.70 +	}
    2.71 +
    2.72  	/* FIXME */
    2.73 -	fprintf(stderr, "Can't handle <unsatisfied>\n");
    2.74 -	exit(1);
    2.75 +	fprintf(stderr, "  Not actually checking <unsatisfiable>\n");
    2.76 +	ctx->in_unsatisfiable = 1;
    2.77  }
    2.78  
    2.79  static void
    2.80 -end_unsatisfied(struct test_context *ctx)
    2.81 +end_unsatisfiable(struct test_context *ctx)
    2.82  {
    2.83 +	ctx->in_unsatisfiable = 0;
    2.84  }
    2.85  
    2.86  static void
    2.87 @@ -323,8 +338,8 @@
    2.88  		start_remove(ctx, atts);
    2.89  	} else if (strcmp(element, "result") == 0) {
    2.90  		start_result(ctx, atts);
    2.91 -	} else if (strcmp(element, "unsatisfied") == 0) {
    2.92 -		start_unsatisfied(ctx, atts);
    2.93 +	} else if (strcmp(element, "unsatisfiable") == 0) {
    2.94 +		start_unsatisfiable(ctx, atts);
    2.95  	} else if (strcmp(element, "package") == 0) {
    2.96  		start_package(ctx, atts);
    2.97  	} else if (strcmp(element, "requires") == 0) {
    2.98 @@ -356,8 +371,8 @@
    2.99  		end_transaction(ctx);
   2.100  	} else if (strcmp(element, "result") == 0) {
   2.101  		end_result(ctx);
   2.102 -	} else if (strcmp(element, "unsatisfied") == 0) {
   2.103 -		end_unsatisfied(ctx);
   2.104 +	} else if (strcmp(element, "unsatisfiable") == 0) {
   2.105 +		end_unsatisfiable(ctx);
   2.106  	}
   2.107  }
   2.108