#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <sys/stat.h>
#include <dirent.h>
#include "conflict.h"
#include "alpm_list.h"
#include "alpm.h"
#include "handle.h"
#include "trans.h"
#include "util.h"
#include "log.h"
#include "deps.h"
static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2,
alpm_depend_t *reason)
{
alpm_conflict_t *conflict;
MALLOC(conflict, sizeof(alpm_conflict_t), return NULL);
conflict->package1_hash = pkg1->name_hash;
conflict->package2_hash = pkg2->name_hash;
STRDUP(conflict->package1, pkg1->name, return NULL);
STRDUP(conflict->package2, pkg2->name, return NULL);
conflict->reason = reason;
return conflict;
}
void _alpm_conflict_free(alpm_conflict_t *conflict)
{
FREE(conflict->package2);
FREE(conflict->package1);
FREE(conflict);
}
alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
{
alpm_conflict_t *newconflict;
CALLOC(newconflict, 1, sizeof(alpm_conflict_t), return NULL);
newconflict->package1_hash = conflict->package1_hash;
newconflict->package2_hash = conflict->package2_hash;
STRDUP(newconflict->package1, conflict->package1, return NULL);
STRDUP(newconflict->package2, conflict->package2, return NULL);
newconflict->reason = conflict->reason;
return newconflict;
}
static int conflict_isin(alpm_conflict_t *needle, alpm_list_t *haystack)
{
alpm_list_t *i;
for(i = haystack; i; i = i->next) {
alpm_conflict_t *conflict = i->data;
if(needle->package1_hash == conflict->package1_hash
&& needle->package2_hash == conflict->package2_hash
&& strcmp(needle->package1, conflict->package1) == 0
&& strcmp(needle->package2, conflict->package2) == 0) {
return 1;
}
}
return 0;
}
static int add_conflict(alpm_handle_t *handle, alpm_list_t **baddeps,
alpm_pkg_t *pkg1, alpm_pkg_t *pkg2, alpm_depend_t *reason)
{
alpm_conflict_t *conflict = conflict_new(pkg1, pkg2, reason);
if(!conflict) {
return -1;
}
if(!conflict_isin(conflict, *baddeps)) {
char *conflict_str = alpm_dep_compute_string(reason);
*baddeps = alpm_list_add(*baddeps, conflict);
_alpm_log(handle, A
|