1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-22 14:22:48 +02:00

qpkg: detect conflicts with installed packages

- prereq.c (installed_conflicts, free_conflicts, prereq): collect list of
  pre-existing conflicts in installed packages
- prereq.c (prereq): check if package being requested already conflicts
- test/instconf: regression test for conflicts with installed packages
- TODO: updated for full support of conflicts. Mention that we're not
  terribly efficient with handling conflicts.
This commit is contained in:
Werner Almesberger 2010-11-21 23:51:35 -03:00
parent be31904f5d
commit c44510ade1
3 changed files with 103 additions and 9 deletions

View File

@ -1,12 +1,8 @@
Still left to do Still left to do
================ ================
- check whether introducing a new package would cause a conflict - consider reducing the size of the lists of conflicts, e.g., by making
them unique via a red-black tree
Update: conflicts among the packages considered for installation are now
checked.
- compile the list of conflicts of installed packages
- handle Provides: - handle Provides:
@ -53,3 +49,10 @@ Done
1172642 calls to comp_id, or 102% of the predicted "good case". 1172642 calls to comp_id, or 102% of the predicted "good case".
- if there are multiple choices, try to prefer more recent versions - if there are multiple choices, try to prefer more recent versions
- 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

View File

@ -16,9 +16,9 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "util.h"
#include "id.h" #include "id.h"
#include "qpkg.h" #include "qpkg.h"
#include "util.h"
#include "prereq.h" #include "prereq.h"
@ -221,6 +221,42 @@ static void resolve(struct list *next_dep, const struct ref *dep,
} }
static struct list *installed_conflicts(void)
{
struct list *list = NULL, *new;
const struct jrb *n;
const struct pkg *pkg;
for (n = jrb_first(packages->root); n != jrb_nil(packages->root);
n = jrb_next(n)) {
pkg = n->val;
if (!pkg)
continue;
if (!(pkg->flags & QPKG_INSTALLED))
continue;
if (!pkg->conflicts) /* optimization */
continue;
new = alloc_type(struct list);
new->refs = pkg->conflicts;
new->next = list;
list = new;
}
return list;
}
static void free_conflicts(struct list *conf)
{
struct list *next;
while (conf) {
next = conf->next;
free(conf);
conf = next;
}
}
struct pkg **prereq(struct pkg *pkg) struct pkg **prereq(struct pkg *pkg)
{ {
struct stack stack = { struct stack stack = {
@ -229,13 +265,18 @@ struct pkg **prereq(struct pkg *pkg)
}; };
struct list conf = { struct list conf = {
.refs = pkg->conflicts, .refs = pkg->conflicts,
.next = NULL .next = installed_conflicts()
}; };
/* @@@ make list of pre-existing conflicts */ if (conflicts(pkg, &conf)) {
fprintf(stderr, "%.*s conflicts with installed packages\n",
ID2PF(pkg->id));
exit(1);
}
pkg->flags |= QPKG_ADDING; pkg->flags |= QPKG_ADDING;
resolve(NULL, pkg->depends, &stack, &conf); resolve(NULL, pkg->depends, &stack, &conf);
pkg->flags &= ~QPKG_ADDING; pkg->flags &= ~QPKG_ADDING;
free(installs); free(installs);
free_conflicts(conf.next);
return best; return best;
} }

50
qpkg/test/instconf Executable file
View File

@ -0,0 +1,50 @@
#!/bin/sh
. ./Common
###############################################################################
qpkg_fail "installed package conflicts with dependency" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Filename: B
Package: A
Version: 0
Architecture: test
Depends: B
Filename: A
Package: C
Version: 0
Architecture: test
Conflicts: B
Status: installed
EOF
expect <<EOF
can't resolve A
EOF
###############################################################################
qpkg_fail "installed package conflicts with initial package" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Filename: B
Package: A
Version: 0
Architecture: test
Depends: B
Filename: A
Package: C
Version: 0
Architecture: test
Conflicts: A
Status: installed
EOF
expect <<EOF
A conflicts with installed packages
EOF