2005-03-22 15:21:12 -05:00
|
|
|
/*
|
|
|
|
* conflict.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04: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>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-22 15:21:12 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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 <string.h>
|
2006-03-02 14:04:40 -05:00
|
|
|
#include <limits.h>
|
2005-03-22 15:21:12 -05:00
|
|
|
#include <sys/stat.h>
|
2009-07-17 09:48:57 -04:00
|
|
|
#include <dirent.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-01-15 10:55:16 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "deps.h"
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
static pmconflict_t *conflict_new(const char *package1, const char *package2,
|
2011-02-16 20:10:53 -05:00
|
|
|
const char *reason)
|
2007-11-18 08:25:43 -05:00
|
|
|
{
|
|
|
|
pmconflict_t *conflict;
|
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
MALLOC(conflict, sizeof(pmconflict_t), return NULL);
|
2007-11-18 08:25:43 -05:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(conflict->package1, package1, return NULL);
|
|
|
|
STRDUP(conflict->package2, package2, return NULL);
|
|
|
|
STRDUP(conflict->reason, reason, return NULL);
|
2007-11-18 08:25:43 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return conflict;
|
2007-11-18 08:25:43 -05:00
|
|
|
}
|
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
void _alpm_conflict_free(pmconflict_t *conflict)
|
|
|
|
{
|
|
|
|
FREE(conflict->package2);
|
|
|
|
FREE(conflict->package1);
|
2009-08-31 10:20:18 -04:00
|
|
|
FREE(conflict->reason);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(conflict);
|
|
|
|
}
|
|
|
|
|
2008-01-25 15:31:20 -05:00
|
|
|
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
|
|
|
|
{
|
|
|
|
pmconflict_t *newconflict;
|
2011-06-07 17:06:16 -04:00
|
|
|
CALLOC(newconflict, 1, sizeof(pmconflict_t), );
|
2008-01-25 15:31:20 -05:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newconflict->package1, conflict->package1, return NULL);
|
|
|
|
STRDUP(newconflict->package2, conflict->package2, return NULL);
|
|
|
|
STRDUP(newconflict->reason, conflict->reason, return NULL);
|
2008-01-25 15:31:20 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return newconflict;
|
2008-01-25 15:31:20 -05:00
|
|
|
}
|
|
|
|
|
2011-02-16 20:10:53 -05:00
|
|
|
static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
|
2007-11-18 08:25:43 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
2011-02-16 20:10:53 -05:00
|
|
|
const char *npkg1 = needle->package1;
|
|
|
|
const char *npkg2 = needle->package2;
|
2007-11-18 08:25:43 -05:00
|
|
|
|
|
|
|
for(i = haystack; i; i = i->next) {
|
|
|
|
pmconflict_t *conflict = i->data;
|
2011-02-16 20:10:53 -05:00
|
|
|
const char *cpkg1 = conflict->package1;
|
|
|
|
const char *cpkg2 = conflict->package2;
|
2010-06-19 04:55:08 -04:00
|
|
|
if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0)
|
|
|
|
|| (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-11-18 08:25:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-11-18 08:25:43 -05:00
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
/** Adds the pkg1/pkg2 conflict to the baddeps list.
|
|
|
|
* @param handle the context handle
|
|
|
|
* @param baddeps list to add conflict to
|
2007-07-19 19:22:45 -04:00
|
|
|
* @param pkg1 first package
|
|
|
|
* @param pkg2 package causing conflict
|
2011-06-07 17:13:58 -04:00
|
|
|
* @param reason reason for this conflict
|
2007-07-19 19:22:45 -04:00
|
|
|
*/
|
2011-06-07 17:13:58 -04:00
|
|
|
static int add_conflict(pmhandle_t *handle, alpm_list_t **baddeps,
|
|
|
|
const char *pkg1, const char *pkg2, const char *reason)
|
2007-03-03 03:13:59 -05:00
|
|
|
{
|
2011-06-07 17:06:16 -04:00
|
|
|
pmconflict_t *conflict = conflict_new(pkg1, pkg2, reason);
|
|
|
|
if(!conflict) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
|
2011-02-16 20:10:53 -05:00
|
|
|
pkg1, pkg2, reason);
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!conflict_isin(conflict, *baddeps)) {
|
2007-11-18 08:25:43 -05:00
|
|
|
*baddeps = alpm_list_add(*baddeps, conflict);
|
2007-07-19 19:22:45 -04:00
|
|
|
} else {
|
2008-01-11 01:01:58 -05:00
|
|
|
_alpm_conflict_free(conflict);
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
2011-06-07 17:06:16 -04:00
|
|
|
return 0;
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
|
2007-07-19 19:22:45 -04:00
|
|
|
/** 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.
|
|
|
|
*
|
2011-06-07 17:13:58 -04:00
|
|
|
* @param handle the context handle
|
2007-07-19 19:22:45 -04:00
|
|
|
* @param list1 first list of packages
|
|
|
|
* @param list2 second list of packages
|
2011-06-07 17:13:58 -04:00
|
|
|
* @param baddeps list to store conflicts
|
2007-07-19 19:22:45 -04:00
|
|
|
* @param order if >= 0 the conflict order is preserved, if < 0 it's reversed
|
|
|
|
*/
|
2011-06-07 17:13:58 -04:00
|
|
|
static void check_conflict(pmhandle_t *handle,
|
|
|
|
alpm_list_t *list1, alpm_list_t *list2,
|
2007-07-19 19:22:45 -04:00
|
|
|
alpm_list_t **baddeps, int order) {
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *i;
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-07-19 19:22:45 -04:00
|
|
|
if(!baddeps) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for(i = list1; i; i = i->next) {
|
|
|
|
pmpkg_t *pkg1 = i->data;
|
|
|
|
const char *pkg1name = alpm_pkg_get_name(pkg1);
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *j;
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-07-19 19:22:45 -04:00
|
|
|
for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
|
|
|
|
const char *conflict = j->data;
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *k;
|
2011-02-16 20:10:53 -05:00
|
|
|
pmdepend_t *parsed_conflict = _alpm_splitdep(conflict);
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-07-19 19:22:45 -04:00
|
|
|
for(k = list2; k; k = k->next) {
|
|
|
|
pmpkg_t *pkg2 = k->data;
|
|
|
|
const char *pkg2name = alpm_pkg_get_name(pkg2);
|
|
|
|
|
|
|
|
if(strcmp(pkg1name, pkg2name) == 0) {
|
|
|
|
/* skip the package we're currently processing */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-16 20:10:53 -05:00
|
|
|
if(_alpm_depcmp(pkg2, parsed_conflict)) {
|
2007-07-19 19:22:45 -04:00
|
|
|
if(order >= 0) {
|
2011-06-07 17:13:58 -04:00
|
|
|
add_conflict(handle, baddeps, pkg1name, pkg2name, conflict);
|
2007-07-19 19:22:45 -04:00
|
|
|
} else {
|
2011-06-07 17:13:58 -04:00
|
|
|
add_conflict(handle, baddeps, pkg2name, pkg1name, conflict);
|
2007-07-19 19:22:45 -04:00
|
|
|
}
|
|
|
|
}
|
2006-02-21 18:55:59 -05:00
|
|
|
}
|
2011-02-16 20:10:53 -05:00
|
|
|
_alpm_dep_free(parsed_conflict);
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 03:57:38 -05:00
|
|
|
/* Check for inter-conflicts */
|
2011-06-07 14:53:53 -04:00
|
|
|
alpm_list_t *_alpm_innerconflicts(pmhandle_t *handle, alpm_list_t *packages)
|
2007-11-20 03:57:38 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *baddeps = NULL;
|
|
|
|
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "check targets vs targets\n");
|
|
|
|
check_conflict(handle, packages, packages, &baddeps, 0);
|
2007-11-20 03:57:38 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return baddeps;
|
2007-11-20 03:57:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for target vs (db - target) conflicts
|
|
|
|
* In case of conflict the package1 field of pmdepconflict_t contains
|
|
|
|
* the target package, package2 field contains the local package
|
|
|
|
*/
|
|
|
|
alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
|
2007-03-03 03:13:59 -05:00
|
|
|
{
|
2007-07-19 19:22:45 -04:00
|
|
|
alpm_list_t *baddeps = NULL;
|
2007-03-03 03:13:59 -05:00
|
|
|
|
|
|
|
if(db == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
|
2011-02-25 09:22:09 -05:00
|
|
|
alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db),
|
2011-01-24 20:49:34 -05:00
|
|
|
packages, _alpm_pkg_cmp);
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-11-20 03:57:38 -05:00
|
|
|
/* two checks to be done here for conflicts */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(db->handle, PM_LOG_DEBUG, "check targets vs db\n");
|
|
|
|
check_conflict(db->handle, packages, dblist, &baddeps, 1);
|
|
|
|
_alpm_log(db->handle, PM_LOG_DEBUG, "check db vs targets\n");
|
|
|
|
check_conflict(db->handle, dblist, packages, &baddeps, -1);
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2007-08-04 11:11:03 -04:00
|
|
|
alpm_list_free(dblist);
|
2011-03-20 20:45:57 -04:00
|
|
|
return baddeps;
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
|
|
|
|
2007-12-09 08:49:34 -05:00
|
|
|
/** Check the package conflicts in a database
|
|
|
|
*
|
2011-06-07 14:53:53 -04:00
|
|
|
* @param handle the context handle
|
2008-08-17 13:30:36 -04:00
|
|
|
* @param pkglist the list of packages to check
|
2007-12-09 08:49:34 -05:00
|
|
|
* @return an alpm_list_t of pmconflict_t
|
|
|
|
*/
|
2011-06-07 14:53:53 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_checkconflicts(pmhandle_t *handle,
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *pkglist)
|
|
|
|
{
|
2011-06-07 14:53:53 -04:00
|
|
|
return _alpm_innerconflicts(handle, pkglist);
|
2007-11-20 03:57:38 -05:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:20:16 -04:00
|
|
|
static const int DIFFERENCE = 0;
|
|
|
|
static const int INTERSECT = 1;
|
|
|
|
/* Returns a set operation on the provided two lists of files.
|
|
|
|
* Pre-condition: both lists are sorted!
|
|
|
|
*
|
|
|
|
* Operations:
|
|
|
|
* DIFFERENCE - a difference operation is performed. filesA - filesB.
|
|
|
|
* INTERSECT - an intersection operation is performed. filesA & filesB.
|
2007-01-18 11:52:57 -05:00
|
|
|
*/
|
2011-03-30 21:20:16 -04:00
|
|
|
static alpm_list_t *filelist_operation(alpm_list_t *filesA, alpm_list_t *filesB,
|
|
|
|
int operation)
|
2007-02-13 03:15:38 -05:00
|
|
|
{
|
|
|
|
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;
|
2011-03-30 21:20:16 -04:00
|
|
|
/* skip directories, we don't care about them */
|
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) {
|
2011-03-30 21:20:16 -04:00
|
|
|
if(operation == DIFFERENCE) {
|
|
|
|
/* item only in filesA, qualifies as a difference */
|
|
|
|
ret = alpm_list_add(ret, strdup(strA));
|
|
|
|
}
|
2007-02-13 21:58:35 -05:00
|
|
|
pA = pA->next;
|
|
|
|
} else if(cmp > 0) {
|
|
|
|
pB = pB->next;
|
|
|
|
} else {
|
2011-03-30 21:20:16 -04:00
|
|
|
if(operation == INTERSECT) {
|
|
|
|
/* item in both, qualifies as an intersect */
|
|
|
|
ret = alpm_list_add(ret, strdup(strA));
|
|
|
|
}
|
2007-02-13 21:58:35 -05:00
|
|
|
pA = pA->next;
|
|
|
|
pB = pB->next;
|
|
|
|
}
|
2007-02-13 03:15:38 -05:00
|
|
|
}
|
|
|
|
}
|
2007-02-18 22:18:59 -05:00
|
|
|
|
2011-03-30 21:20:16 -04:00
|
|
|
/* if doing a difference, ensure we have completely emptied pA */
|
|
|
|
while(operation == DIFFERENCE && pA) {
|
2008-02-11 10:51:34 -05:00
|
|
|
const char *strA = pA->data;
|
|
|
|
/* skip directories */
|
|
|
|
if(strA[strlen(strA)-1] != '/') {
|
|
|
|
ret = alpm_list_add(ret, strdup(strA));
|
|
|
|
}
|
|
|
|
pA = pA->next;
|
|
|
|
}
|
2007-02-18 22:18:59 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-02-13 23:52:17 -05:00
|
|
|
}
|
|
|
|
|
2007-11-18 04:29:55 -05:00
|
|
|
/* Adds pmfileconflict_t to a conflicts list. Pass the conflicts list, type (either
|
|
|
|
* PM_FILECONFLICT_TARGET or PM_FILECONFLICT_FILESYSTEM), a file string, and either
|
2007-02-18 22:18:59 -05:00
|
|
|
* 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
|
|
|
*/
|
2011-06-07 17:13:58 -04:00
|
|
|
static alpm_list_t *add_fileconflict(pmhandle_t *handle,
|
|
|
|
alpm_list_t *conflicts, pmfileconflicttype_t type, const char *filestr,
|
|
|
|
const char *name1, const char *name2)
|
2007-02-13 23:52:17 -05:00
|
|
|
{
|
2007-11-18 04:29:55 -05:00
|
|
|
pmfileconflict_t *conflict;
|
2011-06-07 17:06:16 -04:00
|
|
|
MALLOC(conflict, sizeof(pmfileconflict_t), return NULL);
|
2007-10-29 02:00:52 -04:00
|
|
|
|
2007-02-18 22:18:59 -05:00
|
|
|
conflict->type = type;
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(conflict->target, name1, return NULL);
|
|
|
|
STRDUP(conflict->file, filestr, return NULL);
|
2007-02-18 22:18:59 -05:00
|
|
|
if(name2) {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(conflict->ctarget, name2, return NULL);
|
2007-02-18 22:18:59 -05:00
|
|
|
} else {
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(conflict->ctarget, "", return NULL);
|
2007-02-18 22:18:59 -05:00
|
|
|
}
|
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
conflicts = alpm_list_add(conflicts, conflict);
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
|
2007-02-18 22:18:59 -05:00
|
|
|
filestr, name1, name2 ? name2 : "(filesystem)");
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return conflicts;
|
2007-02-13 23:52:17 -05:00
|
|
|
}
|
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
void _alpm_fileconflict_free(pmfileconflict_t *conflict)
|
|
|
|
{
|
2011-05-04 16:48:47 -04:00
|
|
|
FREE(conflict->ctarget);
|
|
|
|
FREE(conflict->file);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(conflict->target);
|
|
|
|
FREE(conflict);
|
|
|
|
}
|
|
|
|
|
2011-06-07 14:53:53 -04:00
|
|
|
static int dir_belongsto_pkg(const char *root, const char *dirpath,
|
|
|
|
pmpkg_t *pkg)
|
2009-07-17 09:48:57 -04:00
|
|
|
{
|
|
|
|
struct dirent *ent = NULL;
|
|
|
|
struct stat sbuf;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char abspath[PATH_MAX];
|
|
|
|
DIR *dir;
|
|
|
|
|
2011-06-07 14:53:53 -04:00
|
|
|
snprintf(abspath, PATH_MAX, "%s%s", root, dirpath);
|
2009-07-17 09:48:57 -04:00
|
|
|
dir = opendir(abspath);
|
|
|
|
if(dir == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
|
|
const char *name = ent->d_name;
|
|
|
|
|
|
|
|
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
snprintf(path, PATH_MAX, "%s/%s", dirpath, name);
|
2011-06-07 14:53:53 -04:00
|
|
|
snprintf(abspath, PATH_MAX, "%s%s", root, path);
|
2009-07-17 09:48:57 -04:00
|
|
|
if(stat(abspath, &sbuf) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(S_ISDIR(sbuf.st_mode)) {
|
2011-06-07 14:53:53 -04:00
|
|
|
if(dir_belongsto_pkg(root, path, pkg)) {
|
2009-07-17 09:48:57 -04:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
closedir(dir);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
} else {
|
2011-02-08 22:16:04 -05:00
|
|
|
if(alpm_list_find_str(alpm_pkg_get_files(pkg), path)) {
|
2009-07-17 09:48:57 -04:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
closedir(dir);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
|
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 */
|
2011-06-03 14:18:36 -04:00
|
|
|
alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
|
2009-01-02 11:43:05 -05:00
|
|
|
alpm_list_t *upgrade, alpm_list_t *remove)
|
2005-03-22 15:21:12 -05:00
|
|
|
{
|
2009-01-02 11:43:05 -05:00
|
|
|
alpm_list_t *i, *j, *conflicts = NULL;
|
2010-12-08 00:13:36 -05:00
|
|
|
size_t numtargs = alpm_list_count(upgrade);
|
|
|
|
size_t current;
|
2011-06-03 14:18:36 -04:00
|
|
|
pmtrans_t *trans = handle->trans;
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2011-06-03 14:18:36 -04:00
|
|
|
if(!upgrade) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2007-11-11 12:30:16 -05:00
|
|
|
/* TODO this whole function needs a huge change, which hopefully will
|
|
|
|
* 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. */
|
2011-02-08 22:16:04 -05:00
|
|
|
for(current = 0, i = upgrade; i; i = i->next, current++) {
|
2009-01-02 11:43:05 -05:00
|
|
|
alpm_list_t *k, *tmpfiles = NULL;
|
2007-02-13 23:52:17 -05:00
|
|
|
pmpkg_t *p1, *p2, *dbpkg;
|
2011-06-09 14:41:08 -04:00
|
|
|
char path[PATH_MAX];
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2007-02-22 01:36:05 -05:00
|
|
|
p1 = i->data;
|
2007-02-21 23:42:59 -05:00
|
|
|
if(!p1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-09 21:36:42 -05:00
|
|
|
int percent = (current * 100) / numtargs;
|
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
|
2007-08-05 11:50:24 -04:00
|
|
|
numtargs, current);
|
2007-02-13 23:52:17 -05:00
|
|
|
/* CHECK 1: check every target against every target */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "searching for file conflicts: %s\n",
|
2008-01-14 01:59:11 -05:00
|
|
|
alpm_pkg_get_name(p1));
|
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;
|
|
|
|
}
|
2011-03-30 21:20:16 -04:00
|
|
|
tmpfiles = filelist_operation( alpm_pkg_get_files(p1),
|
|
|
|
alpm_pkg_get_files(p2), INTERSECT);
|
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) {
|
2009-01-02 11:43:05 -05:00
|
|
|
snprintf(path, PATH_MAX, "%s%s", handle->root, (char *)k->data);
|
2011-06-07 17:13:58 -04:00
|
|
|
conflicts = add_fileconflict(handle, conflicts, PM_FILECONFLICT_TARGET, path,
|
2008-01-01 20:59:27 -05:00
|
|
|
alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!conflicts) {
|
|
|
|
FREELIST(conflicts);
|
|
|
|
FREELIST(tmpfiles);
|
|
|
|
RET_ERR(handle, PM_ERR_MEMORY, NULL);
|
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2007-11-16 22:15:49 -05:00
|
|
|
FREELIST(tmpfiles);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 02:25:26 -04:00
|
|
|
/* declarations for second check */
|
2007-11-11 12:30:16 -05:00
|
|
|
struct stat lsbuf, sbuf;
|
2007-03-22 02:25:26 -04:00
|
|
|
char *filestr = NULL;
|
|
|
|
|
2006-10-15 19:31:21 -04:00
|
|
|
/* CHECK 2: check every target against the filesystem */
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", p1->name);
|
2011-06-03 14:18:36 -04:00
|
|
|
dbpkg = _alpm_db_get_pkgfromcache(handle->db_local, p1->name);
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
/* Do two different checks here. If the package is currently installed,
|
2007-02-13 23:52:17 -05:00
|
|
|
* 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 */
|
2011-03-30 21:20:16 -04:00
|
|
|
tmpfiles = filelist_operation(alpm_pkg_get_files(p1),
|
|
|
|
alpm_pkg_get_files(dbpkg), DIFFERENCE);
|
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
|
|
|
for(j = tmpfiles; j; j = j->next) {
|
|
|
|
filestr = j->data;
|
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
snprintf(path, PATH_MAX, "%s%s", handle->root, filestr);
|
2007-02-19 21:14:27 -05:00
|
|
|
|
2007-07-13 04:41:40 -04:00
|
|
|
/* stat the file - if it exists, do some checks */
|
2007-11-11 12:30:16 -05:00
|
|
|
if(_alpm_lstat(path, &lsbuf) != 0) {
|
2007-07-13 04:41:40 -04:00
|
|
|
continue;
|
|
|
|
}
|
2007-11-11 12:30:16 -05:00
|
|
|
stat(path, &sbuf);
|
|
|
|
|
2008-01-06 04:59:41 -05:00
|
|
|
if(path[strlen(path)-1] == '/') {
|
|
|
|
if(S_ISDIR(lsbuf.st_mode)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path);
|
2009-01-02 11:43:05 -05:00
|
|
|
continue;
|
2008-01-06 04:59:41 -05:00
|
|
|
} else if(S_ISLNK(lsbuf.st_mode) && S_ISDIR(sbuf.st_mode)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG,
|
2008-01-06 04:59:41 -05:00
|
|
|
"%s is a symlink to a dir, hopefully not a conflict\n", path);
|
2009-01-02 11:43:05 -05:00
|
|
|
continue;
|
2008-01-06 04:59:41 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "checking possible conflict: %s\n", path);
|
2007-02-21 23:42:59 -05:00
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
int resolved_conflict = 0; /* have we acted on this conflict? */
|
|
|
|
|
|
|
|
/* Check remove list (will we remove the conflicting local file?) */
|
|
|
|
for(k = remove; k && !resolved_conflict; k = k->next) {
|
|
|
|
pmpkg_t *rempkg = k->data;
|
|
|
|
if(rempkg && alpm_list_find_str(alpm_pkg_get_files(rempkg), filestr)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "local file will be removed, not a conflict: %s\n", filestr);
|
2009-01-02 11:43:05 -05:00
|
|
|
resolved_conflict = 1;
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Look at all the targets to see if file has changed hands */
|
|
|
|
for(k = upgrade; k && !resolved_conflict; k = k->next) {
|
|
|
|
p2 = k->data;
|
|
|
|
if(!p2 || strcmp(p1->name, p2->name) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-03 14:18:36 -04:00
|
|
|
pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(handle->db_local, p2->name);
|
2009-01-02 11:43:05 -05:00
|
|
|
|
|
|
|
/* localp2->files will be removed (target conflicts are handled by CHECK 1) */
|
|
|
|
if(localp2 && alpm_list_find_str(alpm_pkg_get_files(localp2), filestr)) {
|
|
|
|
/* 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 (whether the file is in backup array or not */
|
2011-06-07 17:06:16 -04:00
|
|
|
handle->trans->skip_remove =
|
|
|
|
alpm_list_add(handle->trans->skip_remove, strdup(filestr));
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr);
|
2009-01-02 11:43:05 -05:00
|
|
|
resolved_conflict = 1;
|
2007-02-22 01:36:05 -05:00
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
|
2009-07-17 09:48:57 -04:00
|
|
|
/* check if all files of the dir belong to the installed pkg */
|
|
|
|
if(!resolved_conflict && S_ISDIR(lsbuf.st_mode) && dbpkg) {
|
|
|
|
char *dir = malloc(strlen(filestr) + 2);
|
|
|
|
sprintf(dir, "%s/", filestr);
|
|
|
|
if(alpm_list_find_str(alpm_pkg_get_files(dbpkg),dir)) {
|
2011-06-07 17:13:58 -04:00
|
|
|
_alpm_log(handle, PM_LOG_DEBUG, "check if all files in %s belongs to %s\n",
|
2009-07-17 09:48:57 -04:00
|
|
|
dir, dbpkg->name);
|
2011-06-07 14:53:53 -04:00
|
|
|
resolved_conflict = dir_belongsto_pkg(handle->root, filestr, dbpkg);
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
free(dir);
|
|
|
|
}
|
|
|
|
|
2009-07-19 10:54:12 -04:00
|
|
|
if(!resolved_conflict && dbpkg) {
|
2011-06-09 14:41:08 -04:00
|
|
|
char *rpath = calloc(PATH_MAX, sizeof(char));
|
2009-07-19 10:54:12 -04:00
|
|
|
if(!realpath(path, rpath)) {
|
2011-06-09 14:41:08 -04:00
|
|
|
free(rpath);
|
2009-07-19 10:54:12 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char *filestr = rpath + strlen(handle->root);
|
|
|
|
if(alpm_list_find_str(alpm_pkg_get_files(dbpkg),filestr)) {
|
|
|
|
resolved_conflict = 1;
|
|
|
|
}
|
|
|
|
free(rpath);
|
|
|
|
}
|
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
if(!resolved_conflict) {
|
2011-06-07 17:13:58 -04:00
|
|
|
conflicts = add_fileconflict(handle, conflicts, PM_FILECONFLICT_FILESYSTEM,
|
2009-01-02 11:43:05 -05:00
|
|
|
path, p1->name, NULL);
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!conflicts) {
|
|
|
|
FREELIST(conflicts);
|
|
|
|
FREELIST(tmpfiles);
|
|
|
|
RET_ERR(handle, PM_ERR_MEMORY, NULL);
|
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2007-11-16 22:15:49 -05:00
|
|
|
FREELIST(tmpfiles);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2011-02-08 22:16:04 -05:00
|
|
|
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
|
|
|
|
numtargs, current);
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return conflicts;
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
|
2007-11-18 08:25:43 -05:00
|
|
|
const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict)
|
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2007-11-18 08:25:43 -05:00
|
|
|
return conflict->package1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
|
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2007-11-18 08:25:43 -05:00
|
|
|
return conflict->package2;
|
|
|
|
}
|
|
|
|
|
2009-08-31 10:20:18 -04:00
|
|
|
const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
|
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2009-08-31 10:20:18 -04:00
|
|
|
return conflict->reason;
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:29:55 -05:00
|
|
|
const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2006-11-22 04:03:41 -05:00
|
|
|
return conflict->target;
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:29:55 -05:00
|
|
|
pmfileconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return -1);
|
2006-11-22 04:03:41 -05:00
|
|
|
return conflict->type;
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:29:55 -05:00
|
|
|
const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2006-11-22 04:03:41 -05:00
|
|
|
return conflict->file;
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:29:55 -05:00
|
|
|
const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(conflict != NULL, return NULL);
|
2006-11-22 04:03:41 -05:00
|
|
|
return conflict->ctarget;
|
|
|
|
}
|
2011-06-07 14:53:53 -04:00
|
|
|
|
2005-03-22 15:21:12 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|