Date: Saturday, March 3, 2007 @ 04:43:17
Author: dan
Path: /home/cvs-pacman/pacman-lib
Modified: lib/libalpm/conflict.c (1.43 -> 1.44)
lib/libalpm/deps.c (1.74 -> 1.75) lib/libalpm/deps.h (1.18 -> 1.19)
lib/libalpm/package.c (1.82 -> 1.83)
lib/libalpm/trans.c (1.40 -> 1.41)
src/pacman/trans.c (1.40 -> 1.41)
* A little more hacking with wchar_t output, but nothing really changed in
it. Eventually we'll make progress.
* Rewrote the _alpm_splitdep function to behave more like all our other
function calls. Use heap instead of stack allocation for the depend struct,
so now it needs to be freed by the caller.
------------------------+
lib/libalpm/conflict.c | 4 -
lib/libalpm/deps.c | 132 +++++++++++++++++++++++++----------------------
lib/libalpm/deps.h | 2
lib/libalpm/package.c | 14 ++--
lib/libalpm/trans.c | 15 ++---
src/pacman/trans.c | 24 ++++++--
6 files changed, 108 insertions(+), 83 deletions(-)
Index: pacman-lib/lib/libalpm/conflict.c
diff -u pacman-lib/lib/libalpm/conflict.c:1.43 pacman-lib/lib/libalpm/conflict.c:1.44
--- pacman-lib/lib/libalpm/conflict.c:1.43 Sat Mar 3 03:13:59 2007
+++ pacman-lib/lib/libalpm/conflict.c Sat Mar 3 04:43:16 2007
@@ -47,14 +47,14 @@
#include "conflict.h"
-/** See if potential conflict 'name' matches package 'pkg'
+/** See if potential conflict 'name' matches package 'pkg'.
* @param target the name of the parent package we're checking
* @param depname the name of the dependency we're checking
* @param pkg the package to check
* @param conflict the name of the possible conflict
* @return A depmissing struct indicating the conflict
* @note The first two paramters are here to simplify the addition
- * of new 'depmiss' objects
+ * of new 'depmiss' objects.
*
* TODO WTF is a 'depmissing' doing indicating a conflict??
*/
Index: pacman-lib/lib/libalpm/deps.c
diff -u pacman-lib/lib/libalpm/deps.c:1.74 pacman-lib/lib/libalpm/deps.c:1.75
--- pacman-lib/lib/libalpm/deps.c:1.74 Sat Mar 3 03:13:59 2007
+++ pacman-lib/lib/libalpm/deps.c Sat Mar 3 04:43:16 2007
@@ -139,18 +139,18 @@
pmpkg_t *p = i->data;
_alpm_log(PM_LOG_DEBUG, " sorting %s", alpm_pkg_get_name(p));
for(j = alpm_pkg_get_depends(p); j; j = j->next) {
- pmdepend_t dep;
+ pmdepend_t *depend = _alpm_splitdep(j->data);
pmpkg_t *q = NULL;
- if(_alpm_splitdep(j->data, &dep)) {
+ if(depend == NULL) {
continue;
}
- /* look for dep.name -- if it's farther down in the list, then
+ /* look for depend->name -- if it's farther down in the list, then
* move it up above p
*/
for(k = i->next; k; k = k->next) {
q = k->data;
const char *qname = alpm_pkg_get_name(q);
- if(!strcmp(dep.name, qname)) {
+ if(!strcmp(depend->name, qname)) {
if(!_alpm_pkg_find(qname, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
@@ -159,7 +159,7 @@
}
for(l = alpm_pkg_get_provides(q); l; l = l->next) {
const char *provname = l->data;
- if(!strcmp(dep.name, provname)) {
+ if(!strcmp(depend->name, provname)) {
if(!_alpm_pkg_find(provname, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
@@ -168,6 +168,7 @@
}
}
}
+ free(depend);
}
if(!_alpm_pkg_find(alpm_pkg_get_name(p), tmptargs)) {
tmptargs = alpm_list_add(tmptargs, p);
@@ -199,7 +200,6 @@
alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
alpm_list_t *packages)
{
- pmdepend_t depend;
alpm_list_t *i, *j, *k, *l;
int found = 0;
alpm_list_t *baddeps = NULL;
@@ -241,19 +241,22 @@
}
for(k = alpm_pkg_get_depends(p); k; k = k->next) {
/* don't break any existing dependencies (possible provides) */
- _alpm_splitdep(k->data, &depend);
+ pmdepend_t *depend = _alpm_splitdep(k->data);
+ if(depend == NULL) {
+ continue;
+ }
/* if oldpkg satisfied this dep, and newpkg doesn't */
- if(_alpm_depcmp(oldpkg, &depend) && !_alpm_depcmp(newpkg, &depend)) {
+ if(_alpm_depcmp(oldpkg, depend) && !_alpm_depcmp(newpkg, depend)) {
/* we've found a dep that was removed... see if any other package
* still contains/provides the dep */
int satisfied = 0;
for(l = packages; l; l = l->next) {
pmpkg_t *pkg = l->data;
- if(_alpm_depcmp(pkg, &depend)) {
+ if(_alpm_depcmp(pkg, depend)) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' has moved from '%s' to '%s'"),
- depend.name, alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(pkg));
+ depend->name, alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(pkg));
satisfied = 1;
break;
}
@@ -270,9 +273,9 @@
continue;
}
- if(_alpm_depcmp(pkg, &depend)) {
+ if(_alpm_depcmp(pkg, depend)) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' satisfied by installed package '%s'"),
- depend.name, alpm_pkg_get_name(pkg));
+ depend->name, alpm_pkg_get_name(pkg));
satisfied = 1;
break;
}
@@ -282,8 +285,8 @@
if(!satisfied) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: updated '%s' won't satisfy a dependency of '%s'"),
alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(p));
- miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_REQUIRED, depend.mod,
- depend.name, depend.version);
+ miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_REQUIRED, depend->mod,
+ depend->name, depend->version);
if(!_alpm_depmiss_isin(miss, baddeps)) {
baddeps = alpm_list_add(baddeps, miss);
} else {
@@ -291,6 +294,7 @@
}
}
}
+ free(depend);
}
}
}
@@ -306,17 +310,21 @@
for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
/* split into name/version pairs */
- _alpm_splitdep((char *)j->data, &depend);
+ pmdepend_t *depend = _alpm_splitdep((char*)j->data);
+ if(depend == NULL) {
+ continue;
+ }
+
found = 0;
/* check database for literal packages */
for(k = _alpm_db_get_pkgcache(db); k && !found; k = k->next) {
pmpkg_t *p = (pmpkg_t *)k->data;
- found = _alpm_depcmp(p, &depend);
+ found = _alpm_depcmp(p, depend);
}
/* check database for provides matches */
if(!found) {
alpm_list_t *m;
- for(m = _alpm_db_whatprovides(db, depend.name); m && !found; m = m->next) {
+ for(m = _alpm_db_whatprovides(db, depend->name); m && !found; m = m->next) {
/* look for a match that isn't one of the packages we're trying
* to install. this way, if we match against a to-be-installed
* package, we'll defer to the NEW one, not the one already
@@ -334,27 +342,28 @@
continue;
}
- found = _alpm_depcmp(p, &depend);
+ found = _alpm_depcmp(p, depend);
}
FREELISTPTR(k);
}
/* check other targets */
for(k = packages; k && !found; k = k->next) {
pmpkg_t *p = k->data;
- found = _alpm_depcmp(p, &depend);
+ found = _alpm_depcmp(p, depend);
}
/* else if still not found... */
if(!found) {
_alpm_log(PM_LOG_DEBUG, _("missing dependency '%s' for package '%s'"),
- depend.name, alpm_pkg_get_name(tp));
- miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), PM_DEP_TYPE_DEPEND, depend.mod,
- depend.name, depend.version);
+ depend->name, alpm_pkg_get_name(tp));
+ miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), PM_DEP_TYPE_DEPEND, depend->mod,
+ depend->name, depend->version);
if(!_alpm_depmiss_isin(miss, baddeps)) {
baddeps = alpm_list_add(baddeps, miss);
} else {
FREE(miss);
}
}
+ free(depend);
}
}
} else if(op == PM_TRANS_TYPE_REMOVE) {
@@ -412,47 +421,49 @@
return(baddeps);
}
-int _alpm_splitdep(char *depstr, pmdepend_t *depend)
+pmdepend_t *_alpm_splitdep(const char *depstring)
{
- char *str = NULL, *ptr = NULL;
+ pmdepend_t *depend;
+ char *ptr = NULL;
- if(depstr == NULL || depend == NULL) {
- return(-1);
+ if(depstring == NULL) {
+ return(NULL);
+ }
+
+ depend = (pmdepend_t *)malloc(sizeof(pmdepend_t));
+ if(depend == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepend_t));
+ return(NULL);
}
- depend->mod = 0;
- depend->name[0] = 0;
- depend->version[0] = 0;
-
- str = strdup(depstr);
-
- if((ptr = strstr(str, ">="))) {
+ /* Find a version comparator if one exists. If it does, set the type and
+ * increment the ptr accordingly so we can copy the right strings. */
+ if((ptr = strstr(depstring, ">="))) {
depend->mod = PM_DEP_MOD_GE;
- } else if((ptr = strstr(str, "<="))) {
+ *ptr = '\0';
+ ptr += 2;
+ } else if((ptr = strstr(depstring, "<="))) {
depend->mod = PM_DEP_MOD_LE;
- } else if((ptr = strstr(str, "="))) {
+ *ptr = '\0';
+ ptr += 2;
+ } else if((ptr = strstr(depstring, "="))) {
depend->mod = PM_DEP_MOD_EQ;
+ *ptr = '\0';
+ ptr += 1;
} else {
- /* no version specified - accept any */
+ /* no version specified - copy in the name and return it */
depend->mod = PM_DEP_MOD_ANY;
- STRNCPY(depend->name, str, PKG_NAME_LEN);
+ strncpy(depend->name, depstring, PKG_NAME_LEN);
+ depend->version[0] = '\0';
+ return(depend);
}
- if(ptr == NULL) {
- FREE(str);
- return(0);
- }
- *ptr = '\0';
- STRNCPY(depend->name, str, PKG_NAME_LEN);
- ptr++;
- if(depend->mod != PM_DEP_MOD_EQ) {
- ptr++;
- }
-
- STRNCPY(depend->version, ptr, PKG_VERSION_LEN);
- FREE(str);
+ /* if we get here, we have a version comparator, copy the right parts
+ * to the right places */
+ strncpy(depend->name, depstring, PKG_NAME_LEN);
+ strncpy(depend->version, ptr, PKG_VERSION_LEN);
- return(0);
+ return(depend);
}
/* These parameters are messy. We check if this package, given a list of
@@ -503,19 +514,19 @@
for(i = targs; i; i = i->next) {
pmpkg_t *pkg = i->data;
for(j = alpm_pkg_get_depends(pkg); j; j = j->next) {
- pmdepend_t depend;
- pmpkg_t *dep;
- if(_alpm_splitdep(j->data, &depend)) {
+ pmdepend_t *depend = _alpm_splitdep(j->data);
+ pmpkg_t *deppkg;
+ if(depend == NULL) {
continue;
}
- dep = _alpm_db_get_pkgfromcache(db, depend.name);
- if(dep == NULL) {
+ deppkg = _alpm_db_get_pkgfromcache(db, depend->name);
+ if(deppkg == NULL) {
/* package not found... look for a provision instead */
- alpm_list_t *provides = _alpm_db_whatprovides(db, depend.name);
+ alpm_list_t *provides = _alpm_db_whatprovides(db, depend->name);
if(!provides) {
/* Not found, that's fine, carry on */
- _alpm_log(PM_LOG_DEBUG, _("cannot find package \"%s\" or anything that provides it!"), depend.name);
+ _alpm_log(PM_LOG_DEBUG, _("cannot find package \"%s\" or anything that provides it!"), depend->name);
continue;
}
for(k = provides; k; k = k->next) {
@@ -531,8 +542,8 @@
}
}
FREELISTPTR(provides);
- } else if(can_remove_package(db, dep, newtargs)) {
- pmpkg_t *pkg = _alpm_pkg_new(dep->name, dep->version);
+ } else if(can_remove_package(db, deppkg, newtargs)) {
+ pmpkg_t *pkg = _alpm_pkg_new(deppkg->name, deppkg->version);
_alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), alpm_pkg_get_name(pkg));
@@ -540,6 +551,7 @@
newtargs = alpm_list_add(newtargs, pkg);
newtargs = _alpm_removedeps(db, newtargs);
}
+ free(depend);
}
}
Index: pacman-lib/lib/libalpm/deps.h
diff -u pacman-lib/lib/libalpm/deps.h:1.18 pacman-lib/lib/libalpm/deps.h:1.19
--- pacman-lib/lib/libalpm/deps.h:1.18 Wed Jan 31 03:10:03 2007
+++ pacman-lib/lib/libalpm/deps.h Sat Mar 3 04:43:16 2007
@@ -49,7 +49,7 @@
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
alpm_list_t *packages);
-int _alpm_splitdep(char *depstr, pmdepend_t *depend);
+pmdepend_t *_alpm_splitdep(const char *depstring);
alpm_list_t *_alpm_removedeps(pmdb_t *db, alpm_list_t *targs);
int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
alpm_list_t *list, alpm_list_t *trail, pmtrans_t *trans,
Index: pacman-lib/lib/libalpm/package.c
diff -u pacman-lib/lib/libalpm/package.c:1.82 pacman-lib/lib/libalpm/package.c:1.83
--- pacman-lib/lib/libalpm/package.c:1.82 Sat Mar 3 03:14:00 2007
+++ pacman-lib/lib/libalpm/package.c Sat Mar 3 04:43:16 2007
@@ -546,16 +546,17 @@
}
pmpkg_t *cachepkg = i->data;
for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) {
- pmdepend_t dep;
+ pmdepend_t *dep;
if(!j->data) {
continue;
}
- if(_alpm_splitdep(j->data, &dep) != 0) {
- continue;
+ dep = _alpm_splitdep(j->data);
+ if(dep == NULL) {
+ continue;
}
-
+
/* check the actual package itself */
- if(strcmp(dep.name, alpm_pkg_get_name(pkg)) == 0) {
+ if(strcmp(dep->name, alpm_pkg_get_name(pkg)) == 0) {
_alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"),
cachepkg->name, pkg->name);
alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg);
@@ -566,7 +567,7 @@
/* check for provisions as well */
for(k = alpm_pkg_get_provides(pkg); k; k = k->next) {
const char *provname = k->data;
- if(strcmp(dep.name, provname) == 0) {
+ if(strcmp(dep->name, provname) == 0) {
_alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s' (provides: %s)"),
alpm_pkg_get_name(cachepkg), alpm_pkg_get_name(pkg), provname);
alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg);
@@ -574,6 +575,7 @@
pkg->requiredby = reqs;
}
}
+ free(dep);
}
}
}
Index: pacman-lib/lib/libalpm/trans.c
diff -u pacman-lib/lib/libalpm/trans.c:1.40 pacman-lib/lib/libalpm/trans.c:1.41
--- pacman-lib/lib/libalpm/trans.c:1.40 Sat Mar 3 03:14:00 2007
+++ pacman-lib/lib/libalpm/trans.c Sat Mar 3 04:43:16 2007
@@ -269,22 +269,22 @@
localdb = alpm_option_get_localdb();
for(i = depends; i; i = i->next) {
- pmdepend_t dep;
- if(_alpm_splitdep(i->data, &dep) != 0) {
+ pmdepend_t* dep = _alpm_splitdep(i->data);
+ if(dep == NULL) {
continue;
}
-
+
if(trans->packages && trans->type == PM_TRANS_TYPE_REMOVE) {
- if(_alpm_pkg_find(dep.name, handle->trans->packages)) {
+ if(_alpm_pkg_find(dep->name, handle->trans->packages)) {
continue;
}
}
- pmpkg_t *deppkg = _alpm_db_get_pkgfromcache(localdb, dep.name);
+ pmpkg_t *deppkg = _alpm_db_get_pkgfromcache(localdb, dep->name);
if(!deppkg) {
int found_provides = 0;
/* look for a provides package */
- alpm_list_t *provides = _alpm_db_whatprovides(localdb, dep.name);
+ alpm_list_t *provides = _alpm_db_whatprovides(localdb, dep->name);
for(j = provides; j; j = j->next) {
if(!j->data) {
continue;
@@ -319,7 +319,7 @@
FREELISTPTR(provides);
if(!found_provides) {
- _alpm_log(PM_LOG_DEBUG, _("could not find dependency '%s'"), dep.name);
+ _alpm_log(PM_LOG_DEBUG, _("could not find dependency '%s'"), dep->name);
continue;
}
}
@@ -341,6 +341,7 @@
_alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"),
alpm_pkg_get_name(deppkg), alpm_pkg_get_version(deppkg));
}
+ free(dep);
}
return(0);
}
Index: pacman-lib/src/pacman/trans.c
diff -u pacman-lib/src/pacman/trans.c:1.40 pacman-lib/src/pacman/trans.c:1.41
--- pacman-lib/src/pacman/trans.c:1.40 Sat Mar 3 03:14:00 2007
+++ pacman-lib/src/pacman/trans.c Sat Mar 3 04:43:16 2007
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <dirent.h>
#include <libintl.h>
+#include <wchar.h>
#include <alpm.h>
/* pacman */
@@ -284,8 +285,9 @@
/* size of line to allocate for text printing (e.g. not progressbar) */
const int infolen = 50;
- int i, digits, textlen, pkglen;
+ int tmp, digits, oprlen, textlen, pkglen;
char *opr = NULL;
+ wchar_t *wcopr = NULL;
if(config->noprogressbar) {
return;
@@ -318,6 +320,7 @@
}
prevpercent=percent;
+ /* set text of message to display */
switch (event) {
case PM_TRANS_PROGRESS_ADD_START:
opr = _("installing");
@@ -332,26 +335,31 @@
opr = _("checking for file conflicts");
break;
}
+ /* convert above strings to wide chars */
+ oprlen = strlen(opr);
+ wcopr = (wchar_t*)calloc(oprlen, sizeof(wchar_t));
+ if(!wcopr) {
+ fprintf(stderr, "malloc failure: could not allocate %d bytes\n",
+ strlen(opr) * sizeof(wchar_t));
+ }
+ oprlen = mbstowcs(wcopr, opr, oprlen);
/* find # of digits in package counts to scale output */
digits = 1;
- i = howmany;
- while((i /= 10)) {
+ tmp = howmany;
+ while((tmp /= 10)) {
++digits;
}
/* determine room left for non-digits text [not ( 1/12) part] */
textlen = infolen - 3 - (2 * digits);
/* room left for package name */
- pkglen = textlen - mbstowcs(NULL, opr, 0) - 1;
+ pkglen = textlen - oprlen - 1;
switch (event) {
case PM_TRANS_PROGRESS_ADD_START:
case PM_TRANS_PROGRESS_UPGRADE_START:
case PM_TRANS_PROGRESS_REMOVE_START:
- /* TODO clean up so digits and pkglen aren't passed twice */
- /* TODO we may need some sort of wchar_t wprintf output here in order
- * to get the lengths right, prinf works on bytes and not chars */
printf("(%2$*1$d/%3$*1$d) %4$s %6$-*5$.*5$s", digits, remain, howmany,
opr, pkglen, pkgname);
break;
@@ -361,6 +369,8 @@
break;
}
+ free(wcopr);
+
/* call refactored fill progress function */
fill_progress(percent, getcols() - infolen);