[Fpkg-cvs] CVS: freepkg/lib depend.c lib.h package.c plist.c
Status: Alpha
Brought to you by:
jlea
|
From: Jeremy L. <jl...@us...> - 2004-04-30 12:48:56
|
jlea 04/04/30 05:48:49
Modified: lib depend.c lib.h package.c plist.c
Log:
Rewrite upgrade_package(), so that it actually stands a chance of working!
Revision Changes Path
1.4 +3 -3 freepkg/lib/depend.c
Index: depend.c
===================================================================
RCS file: /cvsroot/fpkg/freepkg/lib/depend.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- depend.c 30 Apr 2004 09:53:18 -0000 1.3
+++ depend.c 30 Apr 2004 12:48:49 -0000 1.4
@@ -150,16 +150,16 @@
if (dl == NULL)
return FAIL;
PLIST_FOREACH(d, dl) {
- if (d->w != NULL)
- free(d->w);
- d->w = NULL;
if (!NULLSTR(d->pkg) && pkg_mgr_check(d->pkg)) {
d->found = TRUE;
continue;
} else
d->found = FALSE;
+ if (d->w != NULL)
+ free(d->w);
switch (d->type) {
case DEPEND_PKG:
+ d->w = NULL;
break;
case DEPEND_LIB:
d->w = add_which_entry(&wl, WHICH_LIBRARY, d->file);
1.4 +1 -1 freepkg/lib/lib.h
Index: lib.h
===================================================================
RCS file: /cvsroot/fpkg/freepkg/lib/lib.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- lib.h 30 Apr 2004 09:53:18 -0000 1.3
+++ lib.h 30 Apr 2004 12:48:49 -0000 1.4
@@ -472,7 +472,7 @@
error_code delete_plist_entry(plist *, plist_entry *);
plist_t read_plist_entry(char *, char **);
error_code write_plist_entry(FILE *, plist_t, const char *);
-error_code move_plist_entry(plist *, plist_entry *, plist *);
+plist_entry * move_plist_entry(plist *, plist_entry *, plist *);
/* show.c */
#define PKG_SHOW_NONE 0x0000
1.4 +126 -7 freepkg/lib/package.c
Index: package.c
===================================================================
RCS file: /cvsroot/fpkg/freepkg/lib/package.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- package.c 30 Apr 2004 09:53:18 -0000 1.3
+++ package.c 30 Apr 2004 12:48:49 -0000 1.4
@@ -1068,24 +1068,143 @@
}
/*
- * Upgrade one package with another. This just involves moving files from
- * one list to the other. The deletion and addition are taken care of
- * in upgrade_pkg_entry().
+ * Upgrade one package with another. This involves two steps. The first is
+ * to move the dependencies, and the second is moving files from one list to
+ * the other. The deletion and addition are taken care of in
+ * upgrade_pkg_entry().
*/
error_code
upgrade_package(package *from, package *to)
{
+ name_list nl = { PLIST_HEAD_INITIALIZER };
+ name_entry *n;
+ match_list ml = { PLIST_HEAD_INITIALIZER };
+ match_entry *m;
+ depend_entry *d;
+ pkg_entry *pe;
plist_entry *p;
+ char *dir = ".";
+ char tmp[PATH_MAX], rp[PATH_MAX];
if (from == NULL || to == NULL)
return FAIL;
- PLIST_FOREACH(p, &from->plist) {
- if (p->type == PLIST_FILE && p->name && strstr(p->name, ".so.") != NULL) {
- if (move_plist_entry(&from->plist, p, &to->plist))
+ /* XXX: (jlea) Should we have state checks here? */
+ /* XXX: (jlea) We should compare pkgroot_of() the names, and bail if
+ they are not the same? We should also compare prefix! */
+ /*
+ * Step 1: Make a name_list full of the files which other packages
+ * are using as LIB/RUNDEPs. Build a match_list at the same time, since
+ * we're going to need to go over the list of packages again.
+ */
+ PLIST_FOREACH(n, &from->requires) {
+ if ((pe = find_pkg_entry(n->name)) == NULL)
+ continue;
+ if (scan_pkg_entry(pe) == FAIL)
+ return FAIL;
+ check_depend(&pe->pkg->depends);
+ PLIST_FOREACH(d, &pe->pkg->depends) {
+ if (strcmp(d->pkg, from->name) == 0)
+ break;
+ }
+ /* Ooops, these packages are confused! */
+ if (d == NULL) {
+ msg_warn("Invalid dependancy between '%s' and '%s'",
+ n->name, from->name);
+ return FAIL;
+ }
+ add_match_entry(&ml, pe);
+ if (d->w != NULL && !NULLSTR(d->w->file)) {
+ if (add_name_entry(&nl, d->w->file) == NULL)
return FAIL;
- p->merged = TRUE;
}
}
+ /*
+ * Step 2: Check the to package to make sure it installs those files.
+ * XXX: (jlea) We do this to often... Build a function which returns a
+ * name_list of all of the files in a plist!
+ */
+ PLIST_FOREACH(p, &to->plist) {
+ switch(p->type) {
+ case PLIST_CWD:
+ dir = p->name;
+ break;
+ case PLIST_FILE:
+ if (p->ignore)
+ break;
+ snprintf(tmp, PATH_MAX, "%s/%s", dir, p->name);
+ if (!isfile(tmp))
+ break;
+ realpath(tmp, rp);
+ delete_name_entry(&nl, rp);
+ break;
+ default:
+ break;
+ }
+ }
+ if (!PLIST_EMPTY(&nl)) {
+ msg_note("The new package does not contain the following files,"
+ "which are needed to statify some dependencies:\n");
+ PLIST_FOREACH(n, &nl)
+ msg_note("%s\n", n->name);
+ /*
+ * XXX: (jlea) We should figure out which ones from the match_list,
+ * so that we can do recursive upgrades.
+ */
+ free(&ml);
+ free(&nl);
+ return FAIL;
+ }
+ /*
+ * We could move the names across at this point, if we wanted. But this
+ * means that old files, which might have security issues are left
+ * behind...
+ */
+/*
+ PLIST_FOREACH(p, &from->plist) {
+ switch(p->type) {
+ case PLIST_CWD:
+ dir = p->name;
+ break;
+ case PLIST_FILE:
+ if (p->ignore)
+ break;
+ snprintf(tmp, PATH_MAX, "%s/%s", dir, p->name);
+ if (!isfile(tmp))
+ break;
+ realpath(tmp, rp);
+ PLIST_FOREACH(n, &nl) {
+ if (strcmp(tp, n->name) == 0) {
+ if ((p = move_plist_entry(&from->plist,
+ p, &to->plist)) == NULL)
+ return FAIL;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+*/
+ /*
+ * Step 3: Now that we know we have all of the files, go through the
+ * list again, this time changing the requires entries over from 'from'
+ * to 'to'.
+ */
+ PLIST_FOREACH(m, &ml) {
+ PLIST_FOREACH(d, &m->pe->pkg->depends) {
+ if (strcmp(d->pkg, from->name) == 0)
+ break;
+ }
+ if (d == NULL)
+ return FAIL; /* Can't happen */
+ strlcpy(d->pkg, to->name, PATH_MAX);
+ if (d->type == DEPEND_PKG)
+ strlcpy(d->file, to->origin, PATH_MAX);
+ delete_name_entry(&from->requires, m->pe->pkg->name);
+ add_name_entry(&to->requires, m->pe->pkg->name);
+ }
+ free_match(&ml);
+ free_name(&nl);
return SUCCESS;
}
1.2 +9 -6 freepkg/lib/plist.c
Index: plist.c
===================================================================
RCS file: /cvsroot/fpkg/freepkg/lib/plist.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- plist.c 26 Apr 2004 00:06:11 -0000 1.1
+++ plist.c 30 Apr 2004 12:48:49 -0000 1.2
@@ -355,7 +355,7 @@
* Move a plist entry from one plist to another, trying to keep the list
* ordered.
*/
-error_code
+plist_entry *
move_plist_entry(plist *from, plist_entry *move, plist *to)
{
plist_entry *p, *l = NULL;
@@ -363,7 +363,7 @@
PLIST_REMOVE(from, move, l);
/* l will be NULL if we didn't find the element 'move' in 'from'. */
if (l == NULL)
- return FAIL;
+ return NULL;
/*
* Don't insert if there is an existing entry which is the same.
*/
@@ -371,25 +371,28 @@
if (p->type == move->type
&& ((p->name == NULL && move->name == NULL)
|| (p->name != NULL && move->name != NULL
- && strcmp(p->name, move->name) == 0)))
- return SUCCESS;
+ && strcmp(p->name, move->name) == 0))) {
+ free(move);
+ return l;
+ }
}
/*
* We try to insert after the first entry that is the same as the
* element we were after in the last list.
*/
+ move->merged = TRUE;
PLIST_FOREACH(p, to) {
if (p->type == l->type
&& ((p->name == NULL && l->name == NULL)
|| (p->name != NULL && l->name != NULL
&& strcmp(p->name, l->name) == 0))) {
PLIST_INSERT_AFTER(to, p, move);
- return SUCCESS;
+ return l;
}
}
/*
* Finally, just stick it at the end...
*/
PLIST_INSERT_TAIL(to, move);
- return SUCCESS;
+ return l;
}
|