summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/conflict.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/conflict.c')
-rw-r--r--lib/libalpm/conflict.c70
1 files changed, 27 insertions, 43 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index e36844a8..6faced16 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -1,7 +1,7 @@
/*
* conflict.c
*
- * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
* Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
@@ -38,10 +38,10 @@
#include "trans.h"
#include "util.h"
#include "log.h"
-#include "cache.h"
#include "deps.h"
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason)
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2,
+ const char *reason)
{
pmconflict_t *conflict;
@@ -76,20 +76,20 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
return(newconflict);
}
-int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
+static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
{
alpm_list_t *i;
+ const char *npkg1 = needle->package1;
+ const char *npkg2 = needle->package2;
ALPM_LOG_FUNC;
for(i = haystack; i; i = i->next) {
pmconflict_t *conflict = i->data;
- char *cpkg1 = conflict->package1;
- char *cpkg2 = conflict->package2;
- char *npkg1 = needle->package1;
- char *npkg2 = needle->package2;
- if((!strcmp(cpkg1, npkg1) && !strcmp(cpkg2, npkg2))
- || (!strcmp(cpkg1, npkg2) && !strcmp(cpkg2, npkg1))) {
+ const char *cpkg1 = conflict->package1;
+ const char *cpkg2 = conflict->package2;
+ if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0)
+ || (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) {
return(1);
}
}
@@ -97,28 +97,6 @@ int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
return(0);
}
-/** 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 int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
-{
- 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);
- }
- _alpm_dep_free(conf);
- return(match);
-}
-
/** Adds the pkg1/pkg2 conflict to the baddeps list
* @param *baddeps list to add conflict to
* @param pkg1 first package
@@ -128,7 +106,9 @@ static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
const char *pkg2, const char *reason)
{
pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
- if(conflict && !_alpm_conflict_isin(conflict, *baddeps)) {
+ _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
+ pkg1, pkg2, reason);
+ if(conflict && !conflict_isin(conflict, *baddeps)) {
*baddeps = alpm_list_add(*baddeps, conflict);
} else {
_alpm_conflict_free(conflict);
@@ -159,6 +139,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
const char *conflict = j->data;
+ pmdepend_t *parsed_conflict = _alpm_splitdep(conflict);
for(k = list2; k; k = k->next) {
pmpkg_t *pkg2 = k->data;
@@ -169,7 +150,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
continue;
}
- if(does_conflict(pkg1, conflict, pkg2)) {
+ if(_alpm_depcmp(pkg2, parsed_conflict)) {
if(order >= 0) {
add_conflict(baddeps, pkg1name, pkg2name, conflict);
} else {
@@ -177,6 +158,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
}
}
}
+ _alpm_dep_free(parsed_conflict);
}
}
}
@@ -208,8 +190,8 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
return(NULL);
}
- alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db), packages,
- _alpm_pkg_cmp);
+ alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db),
+ packages, _alpm_pkg_cmp);
/* two checks to be done here for conflicts */
_alpm_log(PM_LOG_DEBUG, "check targets vs db\n");
@@ -321,7 +303,7 @@ static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
*/
static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
pmfileconflicttype_t type, const char *filestr,
- const char* name1, const char* name2)
+ const char* name1, const char* name2)
{
pmfileconflict_t *conflict;
MALLOC(conflict, sizeof(pmfileconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
@@ -384,7 +366,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
return(0);
}
} else {
- if(alpm_list_find_str(alpm_pkg_get_files(pkg),path)) {
+ if(alpm_list_find_str(alpm_pkg_get_files(pkg), path)) {
continue;
} else {
closedir(dir);
@@ -403,8 +385,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
alpm_list_t *upgrade, alpm_list_t *remove)
{
alpm_list_t *i, *j, *conflicts = NULL;
- int numtargs = alpm_list_count(upgrade);
- int current;
+ size_t numtargs = alpm_list_count(upgrade);
+ size_t current;
ALPM_LOG_FUNC;
@@ -416,7 +398,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
* be possible with real transactions. Right now we only do half as much
* here as we do when we actually extract files in add.c with our 12
* different cases. */
- for(current = 1, i = upgrade; i; i = i->next, current++) {
+ for(current = 0, i = upgrade; i; i = i->next, current++) {
alpm_list_t *k, *tmpfiles = NULL;
pmpkg_t *p1, *p2, *dbpkg;
char path[PATH_MAX+1];
@@ -426,8 +408,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
continue;
}
- double percent = (double)current / numtargs;
- PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (percent * 100),
+ int percent = (current * 100) / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current);
/* CHECK 1: check every target against every target */
_alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n",
@@ -555,6 +537,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
}
FREELIST(tmpfiles);
}
+ PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
+ numtargs, current);
return(conflicts);
}