summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/conflict.c
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@bibl.u-szeged.hu>2007-11-18 14:25:43 +0100
committerDan McGee <dan@archlinux.org>2007-11-18 19:42:39 +0100
commit2aa7e69da91c1d7a18473cf05df98c92bd1dc747 (patch)
tree1bec8c7ecd1fa012522d2bc311ecefb0f45e1d3b /lib/libalpm/conflict.c
parent65fb99133df10143e07c237f04777e01b443c037 (diff)
downloadpacman-2aa7e69da91c1d7a18473cf05df98c92bd1dc747.tar.gz
pacman-2aa7e69da91c1d7a18473cf05df98c92bd1dc747.tar.xz
Add the pmconflict_t type.
pmdepmissing_t was used for two totally different things : missing dependencies, and dependency conflicts. So this patch simply adds a type for dep conflicts, and convert the code to use it. This fix the TODO in conflict.c : /* TODO WTF is a 'depmissing' doing indicating a conflict? */ Additionally, the code in conflict.c now eliminates the duplicated conflicts. If pkg1 conflicts with pkg2, and pkg2 conflicts with pkg1, only one of them will be stored. However the conflict handling in sync_prepare (sync.c) is still very asymetrical, and very ugly too. This should be improved in the future (there is already a pending patch from Nagy that cleans it a lot). Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Diffstat (limited to 'lib/libalpm/conflict.c')
-rw-r--r--lib/libalpm/conflict.c68
1 files changed, 61 insertions, 7 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index d72dd97a..7268275e 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -43,6 +43,40 @@
#include "cache.h"
#include "deps.h"
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2)
+{
+ pmconflict_t *conflict;
+
+ ALPM_LOG_FUNC;
+
+ MALLOC(conflict, sizeof(pmconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
+
+ strncpy(conflict->package1, package1, PKG_NAME_LEN);
+ strncpy(conflict->package2, package2, PKG_NAME_LEN);
+
+ return(conflict);
+}
+
+int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
+{
+ alpm_list_t *i;
+
+ 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))) {
+ return(1);
+ }
+ }
+
+ return(0);
+}
/** Check if pkg1 conflicts with pkg2
* @param pkg1 package we are looking at
@@ -71,16 +105,14 @@ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
* @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 = _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);
+ pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2);
+ if(conflict && !_alpm_conflict_isin(conflict, *baddeps)) {
+ *baddeps = alpm_list_add(*baddeps, conflict);
} else {
- FREE(miss);
+ FREE(conflict);
}
}
@@ -130,7 +162,7 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
}
}
-/* Returns a alpm_list_t* of pmdepmissing_t pointers. */
+/* Returns a alpm_list_t* of pmconflict_t pointers. */
alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
{
alpm_list_t *baddeps = NULL;
@@ -418,6 +450,28 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans, char *roo
return(conflicts);
}
+const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(conflict != NULL, return(NULL));
+
+ return conflict->package1;
+}
+
+const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(conflict != NULL, return(NULL));
+
+ return conflict->package2;
+}
+
const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;