From be31904f5d4d922fe93ecc638f358c6e28edb713 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 23:24:44 -0300 Subject: [PATCH] qpkg: adding handling of conflicts (in progress) - prereq.c (conflicts): detect conflicts - prereq.c (prereq): pass list of conflicts of initial package - test/conflict: regression test for basic conflict handling - TODO: updated for partial implementation of conflicts --- qpkg/TODO | 3 + qpkg/prereq.c | 17 ++++- qpkg/test/conflict | 157 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 2 deletions(-) create mode 100755 qpkg/test/conflict diff --git a/qpkg/TODO b/qpkg/TODO index e88fadc..f95cc41 100644 --- a/qpkg/TODO +++ b/qpkg/TODO @@ -3,6 +3,9 @@ Still left to do - check whether introducing a new package would cause a conflict + Update: conflicts among the packages considered for installation are now + checked. + - compile the list of conflicts of installed packages - handle Provides: diff --git a/qpkg/prereq.c b/qpkg/prereq.c index 56b8ac9..d7e330a 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -93,6 +93,7 @@ static int satisfies(const struct pkg *pkg, const struct ref *ref) return 0; if (!ref->version) return 1; + /* @@@ error in the database, not qpkg's fault */ assert(pkg->version); cmp = comp_versions(pkg->version, ref->version); //fprintf(stderr, "%.*s <%d> %.*s\n", @@ -112,7 +113,14 @@ static int satisfies(const struct pkg *pkg, const struct ref *ref) static int conflicts(const struct pkg *pkg, const struct list *conf) { - /* @@@ */ + const struct ref *ref; + + while (conf) { + for (ref = conf->refs; ref; ref = ref->next) + if (satisfies(pkg, ref)) + return 1; + conf = conf->next; + } return 0; } @@ -219,9 +227,14 @@ struct pkg **prereq(struct pkg *pkg) .pkg = pkg, .next = NULL }; + struct list conf = { + .refs = pkg->conflicts, + .next = NULL + }; + /* @@@ make list of pre-existing conflicts */ pkg->flags |= QPKG_ADDING; - resolve(NULL, pkg->depends, &stack, NULL); + resolve(NULL, pkg->depends, &stack, &conf); pkg->flags &= ~QPKG_ADDING; free(installs); return best; diff --git a/qpkg/test/conflict b/qpkg/test/conflict new file mode 100755 index 0000000..aa72f81 --- /dev/null +++ b/qpkg/test/conflict @@ -0,0 +1,157 @@ +#!/bin/sh +. ./Common + +############################################################################### + +qpkg_fail "direct conflict precludes resolution" prereq A <= 1) +Filename: foo +EOF +expect <= 1) +Filename: foo +EOF +expect <