2005-03-22 15:21:12 -05:00
|
|
|
/*
|
|
|
|
* conflict.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
|
|
|
|
* Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2006-10-15 20:05:10 -04:00
|
|
|
* Copyright (c) 2006 by Christian Hamar <krics@linuxforum.hu>
|
2005-03-22 15:21:12 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-22 15:21:12 -05:00
|
|
|
#include <stdlib.h>
|
2006-11-22 04:03:41 -05:00
|
|
|
#include <stdio.h>
|
2005-03-22 15:21:12 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2006-03-02 14:04:40 -05:00
|
|
|
#include <limits.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
#if defined(__APPLE__) || defined(__OpenBSD__)
|
|
|
|
#include <sys/syslimits.h>
|
|
|
|
#endif
|
2005-03-22 15:21:12 -05:00
|
|
|
#include <sys/stat.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "conflict.h"
|
2007-01-19 04:28:44 -05:00
|
|
|
#include "alpm_list.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "handle.h"
|
2006-11-20 04:10:23 -05:00
|
|
|
#include "trans.h"
|
2005-03-22 15:21:12 -05:00
|
|
|
#include "util.h"
|
2006-10-15 15:31:03 -04:00
|
|
|
#include "error.h"
|
2006-01-15 10:55:16 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "deps.h"
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-03-03 04:43:16 -05:00
|
|
|
/** See if potential conflict 'name' matches package 'pkg'.
|
2007-03-03 03:13:59 -05:00
|
|
|
* @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
|
2007-03-03 04:43:16 -05:00
|
|
|
* of new 'depmiss' objects.
|
2006-01-15 10:55:16 -05:00
|
|
|
*
|
2007-03-03 03:13:59 -05:00
|
|
|
* TODO WTF is a 'depmissing' doing indicating a conflict??
|
2006-01-15 10:55:16 -05:00
|
|
|
*/
|
2007-03-03 03:13:59 -05:00
|
|
|
static pmdepmissing_t *does_conflict(const char *target, const char *depname,
|
|
|
|
pmpkg_t *pkg, const char *conflict)
|
2006-01-15 10:55:16 -05:00
|
|
|
{
|
2007-03-03 03:13:59 -05:00
|
|
|
alpm_list_t *i;
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
/* 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;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
return(NULL); /* not a conflict */
|
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
static alpm_list_t *chk_pkg_vs_db(alpm_list_t *baddeps, pmpkg_t *pkg, pmdb_t *db)
|
|
|
|
{
|
|
|
|
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);
|
2006-01-15 10:55:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
/* 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 */
|
2006-01-15 10:55:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
|
|
|
|
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);
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
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 */
|
2006-01-15 10:55:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
|
|
|
|
miss = does_conflict(pkgname, targetname, target, conflict);
|
|
|
|
if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
|
|
|
|
baddeps = alpm_list_add(baddeps, miss);
|
|
|
|
} else {
|
|
|
|
FREE(miss);
|
2006-02-21 18:55:59 -05:00
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
2006-02-21 18:55:59 -05:00
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
/* 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) {
|
|
|
|
const char *conflict = j->data;
|
|
|
|
|
|
|
|
|
|
|
|
miss = does_conflict(pkgname, dbpkgname, pkg, conflict);
|
|
|
|
if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
|
|
|
|
baddeps = alpm_list_add(baddeps, miss);
|
|
|
|
} else {
|
|
|
|
FREE(miss);
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
return(baddeps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a alpm_list_t* of pmdepmissing_t pointers.
|
|
|
|
*
|
|
|
|
* conflicts are always name only
|
|
|
|
*/
|
|
|
|
alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
|
|
|
|
{
|
|
|
|
alpm_list_t *i, *baddeps = NULL;
|
|
|
|
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
if(db == NULL) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = packages; i; i = i->next) {
|
|
|
|
pmpkg_t *pkg = i->data;
|
|
|
|
if(pkg == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-03 15:22:48 -05:00
|
|
|
/* run three different conflict checks on each package */
|
2007-03-03 03:13:59 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-03-03 15:22:48 -05:00
|
|
|
/* debug loop */
|
2007-03-03 03:13:59 -05:00
|
|
|
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);
|
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
|
|
|
|
return(baddeps);
|
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
/* Returns a alpm_list_t* of file conflicts.
|
2007-02-13 03:15:38 -05:00
|
|
|
* Hooray for set-intersects!
|
|
|
|
* Pre-condition: both lists are sorted!
|
2007-01-18 11:52:57 -05:00
|
|
|
*/
|
2007-02-13 03:15:38 -05:00
|
|
|
static alpm_list_t *chk_fileconflicts(alpm_list_t *filesA, alpm_list_t *filesB)
|
|
|
|
{
|
|
|
|
alpm_list_t *ret = NULL;
|
|
|
|
alpm_list_t *pA = filesA, *pB = filesB;
|
|
|
|
|
|
|
|
while(pA && pB) {
|
|
|
|
const char *strA = pA->data;
|
|
|
|
const char *strB = pB->data;
|
2007-02-13 21:58:35 -05:00
|
|
|
/* skip directories, we don't care about dir conflicts */
|
2007-02-13 03:15:38 -05:00
|
|
|
if(strA[strlen(strA)-1] == '/') {
|
|
|
|
pA = pA->next;
|
|
|
|
} else if(strB[strlen(strB)-1] == '/') {
|
|
|
|
pB = pB->next;
|
|
|
|
} else {
|
2007-02-13 21:58:35 -05:00
|
|
|
int cmp = strcmp(strA, strB);
|
|
|
|
if(cmp < 0) {
|
|
|
|
/* item only in filesA, ignore it */
|
|
|
|
pA = pA->next;
|
|
|
|
} else if(cmp > 0) {
|
|
|
|
/* item only in filesB, ignore it */
|
|
|
|
pB = pB->next;
|
|
|
|
} else {
|
|
|
|
/* item in both, record it */
|
|
|
|
ret = alpm_list_add(ret, strdup(strA));
|
|
|
|
pA = pA->next;
|
|
|
|
pB = pB->next;
|
|
|
|
}
|
2007-02-13 03:15:38 -05:00
|
|
|
}
|
|
|
|
}
|
2007-02-18 22:18:59 -05:00
|
|
|
|
2007-02-13 03:15:38 -05:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
/* Returns a alpm_list_t* of files that are in filesA but *NOT* in filesB
|
|
|
|
* This is an 'A minus B' set operation
|
|
|
|
* Pre-condition: both lists are sorted!
|
|
|
|
*/
|
|
|
|
static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
|
|
|
|
{
|
|
|
|
alpm_list_t *ret = NULL;
|
|
|
|
alpm_list_t *pA = filesA, *pB = filesB;
|
|
|
|
|
|
|
|
while(pA && pB) {
|
|
|
|
const char *strA = pA->data;
|
|
|
|
const char *strB = pB->data;
|
|
|
|
/* skip directories, we don't care about dir conflicts */
|
|
|
|
if(strA[strlen(strA)-1] == '/') {
|
|
|
|
pA = pA->next;
|
|
|
|
} else if(strB[strlen(strB)-1] == '/') {
|
|
|
|
pB = pB->next;
|
|
|
|
} else {
|
|
|
|
int cmp = strcmp(strA, strB);
|
|
|
|
if(cmp < 0) {
|
|
|
|
/* item only in filesA, record it */
|
|
|
|
ret = alpm_list_add(ret, strdup(strA));
|
|
|
|
pA = pA->next;
|
|
|
|
} else if(cmp > 0) {
|
|
|
|
/* item only in fileB, but this means nothing */
|
|
|
|
pB = pB->next;
|
|
|
|
} else {
|
|
|
|
/* item in both, ignore it */
|
|
|
|
pA = pA->next;
|
|
|
|
pB = pB->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-18 22:18:59 -05:00
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2007-02-18 22:18:59 -05:00
|
|
|
/* Adds pmconflict_t to a conflicts list. Pass the conflicts list, type (either
|
|
|
|
* PM_CONFLICT_TYPE_TARGET or PM_CONFLICT_TYPE_FILE), a file string, and either
|
|
|
|
* two package names or one package name and NULL. This is a wrapper for former
|
|
|
|
* functionality that was done inline.
|
2007-02-13 23:52:17 -05:00
|
|
|
*/
|
2007-02-18 22:18:59 -05:00
|
|
|
static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
|
2007-03-03 03:13:59 -05:00
|
|
|
pmconflicttype_t type, const char *filestr,
|
|
|
|
const char* name1, const char* name2)
|
2007-02-13 23:52:17 -05:00
|
|
|
{
|
|
|
|
pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
|
|
|
|
if(conflict == NULL) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"),
|
|
|
|
sizeof(pmconflict_t));
|
|
|
|
return(conflicts);
|
|
|
|
}
|
2007-02-18 22:18:59 -05:00
|
|
|
conflict->type = type;
|
2007-04-29 12:03:09 -04:00
|
|
|
strncpy(conflict->target, name1, PKG_NAME_LEN);
|
|
|
|
strncpy(conflict->file, filestr, CONFLICT_FILE_LEN);
|
2007-02-18 22:18:59 -05:00
|
|
|
if(name2) {
|
2007-04-29 12:03:09 -04:00
|
|
|
strncpy(conflict->ctarget, name2, PKG_NAME_LEN);
|
2007-02-18 22:18:59 -05:00
|
|
|
} else {
|
|
|
|
conflict->ctarget[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
conflicts = alpm_list_add(conflicts, conflict);
|
2007-02-18 22:18:59 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "found file conflict %s, packages %s and %s",
|
|
|
|
filestr, name1, name2 ? name2 : "(filesystem)");
|
2007-02-13 23:52:17 -05:00
|
|
|
|
|
|
|
return(conflicts);
|
|
|
|
}
|
|
|
|
|
2007-03-22 02:25:26 -04:00
|
|
|
/* Find file conflicts that may occur during the transaction with two checks:
|
|
|
|
* 1: check every target against every target
|
|
|
|
* 2: check every target against the filesystem */
|
2007-02-19 21:14:27 -05:00
|
|
|
alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
|
2005-03-22 15:21:12 -05:00
|
|
|
{
|
2007-03-22 02:25:26 -04:00
|
|
|
alpm_list_t *i, *conflicts = NULL;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *targets = trans->packages;
|
2007-02-13 23:52:17 -05:00
|
|
|
int numtargs = alpm_list_count(targets);
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2005-03-22 15:21:12 -05:00
|
|
|
if(db == NULL || targets == NULL || root == NULL) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2005-03-22 15:21:12 -05:00
|
|
|
for(i = targets; i; i = i->next) {
|
2007-03-22 02:25:26 -04:00
|
|
|
alpm_list_t *j, *k, *tmpfiles = NULL;
|
2007-02-13 23:52:17 -05:00
|
|
|
pmpkg_t *p1, *p2, *dbpkg;
|
|
|
|
char path[PATH_MAX+1];
|
|
|
|
|
2007-02-22 01:36:05 -05:00
|
|
|
p1 = i->data;
|
2007-02-21 23:42:59 -05:00
|
|
|
if(!p1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 02:25:26 -04:00
|
|
|
double percent = (double)(alpm_list_count(targets) - alpm_list_count(i) + 1)
|
2007-02-13 23:52:17 -05:00
|
|
|
/ alpm_list_count(targets);
|
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (percent * 100),
|
|
|
|
numtargs, (numtargs - alpm_list_count(i) +1));
|
|
|
|
/* CHECK 1: check every target against every target */
|
2007-02-13 03:15:38 -05:00
|
|
|
for(j = i->next; j; j = j->next) {
|
2007-02-22 01:36:05 -05:00
|
|
|
p2 = j->data;
|
|
|
|
if(!p2) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s and %s",
|
|
|
|
alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
|
|
|
|
tmpfiles = chk_fileconflicts(alpm_pkg_get_files(p1), alpm_pkg_get_files(p2));
|
2007-02-13 03:15:38 -05:00
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
if(tmpfiles) {
|
|
|
|
for(k = tmpfiles; k; k = k->next) {
|
2007-02-22 01:36:05 -05:00
|
|
|
snprintf(path, PATH_MAX, "%s%s", root, (char *)k->data);
|
2007-03-03 03:13:59 -05:00
|
|
|
conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_TARGET, path,
|
|
|
|
alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2007-02-13 23:52:17 -05:00
|
|
|
alpm_list_free_inner(tmpfiles, &free);
|
|
|
|
alpm_list_free(tmpfiles);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 02:25:26 -04:00
|
|
|
/* declarations for second check */
|
|
|
|
struct stat buf;
|
|
|
|
char *filestr = NULL;
|
|
|
|
|
2006-10-15 19:31:21 -04:00
|
|
|
/* CHECK 2: check every target against the filesystem */
|
2007-02-18 22:18:59 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s", p1->name);
|
2007-02-13 23:52:17 -05:00
|
|
|
dbpkg = _alpm_db_get_pkgfromcache(db, p1->name);
|
|
|
|
|
|
|
|
/* Do two different checks here. f the package is currently installed,
|
|
|
|
* then only check files that are new in the new package. If the package
|
|
|
|
* is not currently installed, then simply stat the whole filelist */
|
|
|
|
if(dbpkg) {
|
|
|
|
/* older ver of package currently installed */
|
2007-03-03 03:13:59 -05:00
|
|
|
tmpfiles = chk_filedifference(alpm_pkg_get_files(p1), alpm_pkg_get_files(dbpkg));
|
2007-02-13 23:52:17 -05:00
|
|
|
} else {
|
|
|
|
/* no version of package currently installed */
|
2007-03-03 03:13:59 -05:00
|
|
|
tmpfiles = alpm_list_strdup(alpm_pkg_get_files(p1));
|
2007-02-19 21:14:27 -05:00
|
|
|
}
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
/* loop over each file to be installed */
|
|
|
|
for(j = tmpfiles; j; j = j->next) {
|
|
|
|
filestr = j->data;
|
|
|
|
|
|
|
|
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)) {
|
2007-02-22 01:36:05 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "checking possible conflict: %s", path);
|
2007-02-21 01:44:14 -05:00
|
|
|
|
2007-03-22 02:25:26 -04:00
|
|
|
/* 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 */
|
|
|
|
if(dbpkg) {
|
|
|
|
struct stat buf2;
|
|
|
|
char str[PATH_MAX+1];
|
|
|
|
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) {
|
|
|
|
ok = 1;
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "conflict was a symlink: %s", path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ok == 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
/* Look at all the targets to see if file has changed hands */
|
2007-02-22 01:36:05 -05:00
|
|
|
int resolved_conflict = 0; /* have we acted on this conflict? */
|
2007-02-19 21:14:27 -05:00
|
|
|
for(k = targets; k; k = k->next) {
|
2007-02-22 01:36:05 -05:00
|
|
|
p2 = k->data;
|
|
|
|
if(!p2 || strcmp(p1->name, p2->name) == 0) {
|
2007-02-19 21:14:27 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-21 23:42:59 -05:00
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(db, p2->name);
|
2007-02-22 01:36:05 -05:00
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
/* Check if it used to exist in a package, but doesn't anymore */
|
2007-02-22 01:36:05 -05:00
|
|
|
alpm_list_t *pkgfiles, *localfiles; /* added for readability */
|
|
|
|
pkgfiles = alpm_pkg_get_files(p2);
|
|
|
|
localfiles = alpm_pkg_get_files(localp2);
|
|
|
|
|
|
|
|
if(localp2 && !alpm_list_find_str(pkgfiles, filestr)
|
|
|
|
&& alpm_list_find_str(localfiles, filestr)) {
|
2007-02-19 21:14:27 -05:00
|
|
|
/* check if the file is now in the backup array */
|
|
|
|
if(alpm_list_find_str(alpm_pkg_get_backup(p1), filestr)) {
|
|
|
|
/* 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);
|
2007-02-22 01:36:05 -05:00
|
|
|
resolved_conflict = 1;
|
|
|
|
break;
|
2007-02-19 21:14:27 -05:00
|
|
|
} else {
|
|
|
|
/* skip removal of file, but not add. this will prevent a second
|
|
|
|
* 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);
|
2007-02-22 01:36:05 -05:00
|
|
|
resolved_conflict = 1;
|
|
|
|
break;
|
2007-02-19 21:14:27 -05:00
|
|
|
}
|
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2007-02-22 01:36:05 -05:00
|
|
|
if(!resolved_conflict) {
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "file found in conflict: %s", path);
|
|
|
|
conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE,
|
|
|
|
path, p1->name, NULL);
|
|
|
|
}
|
2007-02-21 23:42:59 -05:00
|
|
|
} else {
|
2007-07-10 11:31:13 -04:00
|
|
|
if(S_ISDIR(buf.st_mode))
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict", path);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
}
|
2007-02-19 21:14:27 -05:00
|
|
|
alpm_list_free_inner(tmpfiles, &free);
|
|
|
|
alpm_list_free(tmpfiles);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(conflicts);
|
|
|
|
}
|
|
|
|
|
2007-01-30 02:47:19 -05:00
|
|
|
const char SYMEXPORT *alpm_conflict_get_target(pmconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(conflict != NULL, return(NULL));
|
|
|
|
|
|
|
|
return conflict->target;
|
|
|
|
}
|
|
|
|
|
2007-01-30 02:47:19 -05:00
|
|
|
pmconflicttype_t SYMEXPORT alpm_conflict_get_type(pmconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(conflict != NULL, return(-1));
|
|
|
|
|
|
|
|
return conflict->type;
|
|
|
|
}
|
|
|
|
|
2007-01-30 02:47:19 -05:00
|
|
|
const char SYMEXPORT *alpm_conflict_get_file(pmconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(conflict != NULL, return(NULL));
|
|
|
|
|
|
|
|
return conflict->file;
|
|
|
|
}
|
|
|
|
|
2007-01-30 02:47:19 -05:00
|
|
|
const char SYMEXPORT *alpm_conflict_get_ctarget(pmconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(conflict != NULL, return(NULL));
|
|
|
|
|
|
|
|
return conflict->ctarget;
|
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|