Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/conflict.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/conflict.c')
-rw-r--r--lib/libalpm/conflict.c300
1 files changed, 99 insertions, 201 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 3755fcd7..d09c996d 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -30,9 +30,6 @@
#include <unistd.h>
#include <string.h>
#include <limits.h>
-#if defined(__APPLE__) || defined(__OpenBSD__)
-#include <sys/syslimits.h>
-#endif
#include <sys/stat.h>
/* libalpm */
@@ -47,190 +44,96 @@
#include "deps.h"
-/** 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.
- *
- * TODO WTF is a 'depmissing' doing indicating a conflict??
+/** Check if pkg1 conflicts with pkg2
+ * @param pkg1 package we are looking at
+ * @param conflict name of the possible conflict
+ * @param pkg2 package to check
+ * @return 0 for no conflict, non-zero otherwise
*/
-static pmdepmissing_t *does_conflict(const char *target, const char *depname,
- pmpkg_t *pkg, const char *conflict)
+static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
{
- alpm_list_t *i;
-
- /* check the actual package name, easy */
- if(strcmp(alpm_pkg_get_name(pkg), conflict) == 0) {
- _alpm_log(PM_LOG_DEBUG, _(" found conflict '%s' : package '%s'"), conflict, target);
- return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT,
- PM_DEP_MOD_ANY, depname, NULL));
- } else {
- /* check what this package provides, harder */
- for(i = alpm_pkg_get_provides(pkg); i; i = i->next) {
- const char *provision = i->data;
-
- if(strcmp(provision, conflict) == 0) {
- _alpm_log(PM_LOG_DEBUG, _(" found conflict '%s' : package '%s' provides '%s'"),
- conflict, target, provision);
- return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT,
- PM_DEP_MOD_ANY, depname, NULL));
- }
- }
+ const char *pkg1name = alpm_pkg_get_name(pkg1);
+ const char *pkg2name = alpm_pkg_get_name(pkg2);
+ pmdepend_t *conf = alpm_splitdep(conflict);
+ int match = 0;
+
+ match = alpm_depcmp(pkg2, conf);
+ if(match) {
+ _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
+ pkg1name, pkg2name, conflict);
}
- return(NULL); /* not a conflict */
+ FREE(conf);
+ return(match);
}
-static alpm_list_t *chk_pkg_vs_db(alpm_list_t *baddeps, pmpkg_t *pkg, pmdb_t *db)
+/** Adds the pkg1/pkg2 conflict to the baddeps list
+ * @param *baddeps list to add conflict to
+ * @param pkg1 first package
+ * @param pkg2 package causing conflict
+ */
+/* TODO WTF is a 'depmissing' doing indicating a conflict? */
+static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
+ const char *pkg2)
{
- pmdepmissing_t *miss = NULL;
- const char *pkgname;
- alpm_list_t *i, *j;
-
- pkgname = alpm_pkg_get_name(pkg);
-
- for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) {
- const char *conflict = i->data;
-
- if(strcmp(pkgname, conflict) == 0) {
- /* a package cannot conflict with itself -- that's just not nice */
- _alpm_log(PM_LOG_DEBUG, _("package '%s' conflicts with itself - packaging error"),
- pkgname);
- continue;
- }
-
- /* CHECK 1: check targets against database */
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: target '%s' vs db"), pkgname);
-
- for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
- pmpkg_t *dbpkg = j->data;
-
- if(strcmp(alpm_pkg_get_name(dbpkg), pkgname) == 0) {
- /* skip the package we're currently processing */
- continue;
- }
-
- miss = does_conflict(pkgname, alpm_pkg_get_name(dbpkg), dbpkg, conflict);
- if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- }
+ pmdepmissing_t *miss = _alpm_depmiss_new(pkg1, PM_DEP_TYPE_CONFLICT,
+ PM_DEP_MOD_ANY, pkg2, NULL);
+ if(miss && !_alpm_depmiss_isin(miss, *baddeps)) {
+ *baddeps = alpm_list_add(*baddeps, miss);
+ } else {
+ FREE(miss);
}
- return(baddeps);
}
-static alpm_list_t *chk_pkg_vs_targets(alpm_list_t *baddeps,
- pmpkg_t *pkg, pmdb_t *db,
- alpm_list_t *targets)
-{
- pmdepmissing_t *miss = NULL;
- const char *pkgname;
- alpm_list_t *i, *j;
-
- pkgname = alpm_pkg_get_name(pkg);
-
- for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) {
- const char *conflict = i->data;
-
- if(strcmp(pkgname, conflict) == 0) {
- /* a package cannot conflict with itself -- that's just not nice */
- _alpm_log(PM_LOG_DEBUG, _("package '%s' conflicts with itself - packaging error"),
- pkgname);
- continue;
- }
-
- /* CHECK 2: check targets against targets */
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: target '%s' vs all targets"), pkgname);
-
- for(j = targets; j; j = j->next) {
- const char *targetname;
- pmpkg_t *target = j->data;
- targetname = alpm_pkg_get_name(target);
-
- if(strcmp(targetname, pkgname) == 0) {
- /* skip the package we're currently processing */
- continue;
- }
+/** Check if packages from list1 conflict with packages from list2.
+ * This looks at the conflicts fields of all packages from list1, and sees
+ * if they match packages from list2.
+ * If a conflict (pkg1, pkg2) is found, it is added to the baddeps list
+ * in this order if order >= 0, or reverse order (pkg2,pkg1) otherwise.
+ *
+ * @param list1 first list of packages
+ * @param list2 second list of packages
+ * @param *baddeps list to store conflicts
+ * @param order if >= 0 the conflict order is preserved, if < 0 it's reversed
+ */
+static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
+ alpm_list_t **baddeps, int order) {
+ alpm_list_t *i, *j, *k;
- miss = does_conflict(pkgname, targetname, target, conflict);
- if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- }
+ if(!baddeps) {
+ return;
}
- return(baddeps);
-}
-
-static alpm_list_t *chk_db_vs_targets(alpm_list_t *baddeps, pmpkg_t *pkg,
- pmdb_t *db, alpm_list_t *targets)
-{
- pmdepmissing_t *miss = NULL;
- const char *pkgname;
- alpm_list_t *i, *j;
-
- pkgname = alpm_pkg_get_name(pkg);
-
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: db vs target '%s'"), pkgname);
-
- for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
- alpm_list_t *conflicts = NULL;
- const char *dbpkgname;
+ for(i = list1; i; i = i->next) {
+ pmpkg_t *pkg1 = i->data;
+ const char *pkg1name = alpm_pkg_get_name(pkg1);
- pmpkg_t *dbpkg = i->data;
- dbpkgname = alpm_pkg_get_name(dbpkg);
-
- if(strcmp(dbpkgname, pkgname) == 0) {
- /* skip the package we're currently processing */
- continue;
- }
-
- /* is this db package in the targets? if so use the
- * new package's conflict list to pick up new changes */
- int use_newconflicts = 0;
- for(j = targets; j; j = j->next) {
- pmpkg_t *targ = j->data;
- if(strcmp(alpm_pkg_get_name(targ), dbpkgname) == 0) {
- _alpm_log(PM_LOG_DEBUG, _("target '%s' is also in target list, using NEW conflicts"),
- dbpkgname);
- conflicts = alpm_pkg_get_conflicts(targ);
- use_newconflicts = 1;
- break;
- }
- }
- /* if we didn't find newer conflicts, use the original list */
- if(!use_newconflicts) {
- conflicts = alpm_pkg_get_conflicts(dbpkg);
- }
-
- for(j = conflicts; j; j = j->next) {
+ for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
const char *conflict = j->data;
+ for(k = list2; k; k = k->next) {
+ pmpkg_t *pkg2 = k->data;
+ const char *pkg2name = alpm_pkg_get_name(pkg2);
- miss = does_conflict(pkgname, dbpkgname, pkg, conflict);
- if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
+ if(strcmp(pkg1name, pkg2name) == 0) {
+ /* skip the package we're currently processing */
+ continue;
+ }
+
+ if(does_conflict(pkg1, conflict, pkg2)) {
+ if(order >= 0) {
+ add_conflict(baddeps, pkg1name, pkg2name);
+ } else {
+ add_conflict(baddeps, pkg2name, pkg1name);
+ }
+ }
}
}
}
- return(baddeps);
}
-/* Returns a alpm_list_t* of pmdepmissing_t pointers.
- *
- * conflicts are always name only
- */
+/* Returns a alpm_list_t* of pmdepmissing_t pointers. */
alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
{
- alpm_list_t *i, *baddeps = NULL;
+ alpm_list_t *baddeps = NULL;
ALPM_LOG_FUNC;
@@ -238,28 +141,21 @@ alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
return(NULL);
}
- for(i = packages; i; i = i->next) {
- pmpkg_t *pkg = i->data;
- if(pkg == NULL) {
- continue;
- }
+ alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db), packages,
+ _alpm_pkg_cmp);
- /* run three different conflict checks on each package */
- baddeps = chk_pkg_vs_db(baddeps, pkg, db);
- baddeps = chk_pkg_vs_targets(baddeps, pkg, db, packages);
- baddeps = chk_db_vs_targets(baddeps, pkg, db, packages);
- }
-
- /* debug loop */
- for(i = baddeps; i; i = i->next) {
- pmdepmissing_t *miss = i->data;
- _alpm_log(PM_LOG_DEBUG, _("\tCONFLICTS:: %s conflicts with %s"), miss->target, miss->depend.name);
- }
+ /* three checks to be done here for conflicts */
+ _alpm_log(PM_LOG_DEBUG, "check targets vs db\n");
+ check_conflict(packages, dblist, &baddeps, 1);
+ _alpm_log(PM_LOG_DEBUG, "check db vs targets\n");
+ check_conflict(dblist, packages, &baddeps, -1);
+ _alpm_log(PM_LOG_DEBUG, "check targets vs targets\n");
+ check_conflict(packages, packages, &baddeps, 0);
+ alpm_list_free(dblist);
return(baddeps);
}
-
/* Returns a alpm_list_t* of file conflicts.
* Hooray for set-intersects!
* Pre-condition: both lists are sorted!
@@ -345,7 +241,7 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
{
pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
if(conflict == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"),
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"),
sizeof(pmconflict_t));
return(conflicts);
}
@@ -359,7 +255,7 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
}
conflicts = alpm_list_add(conflicts, conflict);
- _alpm_log(PM_LOG_DEBUG, "found file conflict %s, packages %s and %s",
+ _alpm_log(PM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
filestr, name1, name2 ? name2 : "(filesystem)");
return(conflicts);
@@ -373,6 +269,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
alpm_list_t *i, *conflicts = NULL;
alpm_list_t *targets = trans->packages;
int numtargs = alpm_list_count(targets);
+ int current;
ALPM_LOG_FUNC;
@@ -380,7 +277,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
return(NULL);
}
- for(i = targets; i; i = i->next) {
+ for(current = 1, i = targets; i; i = i->next, current++) {
alpm_list_t *j, *k, *tmpfiles = NULL;
pmpkg_t *p1, *p2, *dbpkg;
char path[PATH_MAX+1];
@@ -390,17 +287,16 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
continue;
}
- double percent = (double)(alpm_list_count(targets) - alpm_list_count(i) + 1)
- / alpm_list_count(targets);
+ double percent = (double)current / numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (percent * 100),
- numtargs, (numtargs - alpm_list_count(i) +1));
+ numtargs, current);
/* CHECK 1: check every target against every target */
for(j = i->next; j; j = j->next) {
p2 = j->data;
if(!p2) {
continue;
}
- _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s and %s",
+ _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s and %s\n",
alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
tmpfiles = chk_fileconflicts(alpm_pkg_get_files(p1), alpm_pkg_get_files(p2));
@@ -420,7 +316,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
char *filestr = NULL;
/* CHECK 2: check every target against the filesystem */
- _alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s", p1->name);
+ _alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", p1->name);
dbpkg = _alpm_db_get_pkgfromcache(db, p1->name);
/* Do two different checks here. f the package is currently installed,
@@ -440,9 +336,14 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
snprintf(path, PATH_MAX, "%s%s", root, filestr);
- /* stat the file - if it exists and is not a dir, do some checks */
- if(lstat(path, &buf) == 0 && !S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG, "checking possible conflict: %s", path);
+ /* stat the file - if it exists, do some checks */
+ if(lstat(path, &buf) != 0) {
+ continue;
+ }
+ if(S_ISDIR(buf.st_mode)) {
+ _alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path);
+ } else {
+ _alpm_log(PM_LOG_DEBUG, "checking possible conflict: %s\n", path);
/* Make sure the possible conflict is not a symlink that points to a
* path in the old package. This is kind of dirty with inode usage */
@@ -452,10 +353,9 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
unsigned ok = 0;
for(k = dbpkg->files; k; k = k->next) {
snprintf(str, PATH_MAX, "%s%s", root, (char*)k->data);
- lstat(str, &buf2);
- if(buf.st_ino == buf2.st_ino) {
+ if(!lstat(str, &buf2) && buf.st_ino == buf2.st_ino) {
ok = 1;
- _alpm_log(PM_LOG_DEBUG, "conflict was a symlink: %s", path);
+ _alpm_log(PM_LOG_DEBUG, "conflict was a symlink: %s\n", path);
break;
}
}
@@ -486,7 +386,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
/* keep file intact if it is in backup array */
trans->skip_add = alpm_list_add(trans->skip_add, strdup(path));
trans->skip_remove = alpm_list_add(trans->skip_remove, strdup(path));
- _alpm_log(PM_LOG_DEBUG, "file in backup array, adding to add and remove skiplist: %s", filestr);
+ _alpm_log(PM_LOG_DEBUG, "file in backup array, adding to add and remove skiplist: %s\n", filestr);
resolved_conflict = 1;
break;
} else {
@@ -494,19 +394,17 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
* package from removing the file when it was already installed
* by its new owner */
trans->skip_remove = alpm_list_add(trans->skip_remove, strdup(path));
- _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s", filestr);
+ _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr);
resolved_conflict = 1;
break;
}
}
}
if(!resolved_conflict) {
- _alpm_log(PM_LOG_DEBUG, "file found in conflict: %s", path);
+ _alpm_log(PM_LOG_DEBUG, "file found in conflict: %s\n", path);
conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE,
path, p1->name, NULL);
}
- } else {
- _alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict", path);
}
}
alpm_list_free_inner(tmpfiles, &free);