2005-03-22 15:21:12 -05:00
|
|
|
/*
|
|
|
|
* conflict.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2012-02-20 07:53:03 -05:00
|
|
|
* Copyright (c) 2006-2012 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 <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"
|
2011-06-16 14:16:49 -04:00
|
|
|
#include "alpm.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"
|
2012-07-12 16:29:59 -04:00
|
|
|
#include "filelist.h"
|
2005-03-22 15:21:12 -05:00
|
|
|
|
2011-08-09 00:25:45 -04:00
|
|
|
static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2,
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *reason)
|
2007-11-18 08:25:43 -05:00
|
|
|
{
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *conflict;
|
2007-11-18 08:25:43 -05:00
|
|
|
|
2011-06-28 00:33:55 -04:00
|
|
|
MALLOC(conflict, sizeof(alpm_conflict_t), return NULL);
|
2007-11-18 08:25:43 -05:00
|
|
|
|
2011-08-09 00:25:45 -04:00
|
|
|
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);
|
2011-08-09 02:00:16 -04:00
|
|
|
conflict->reason = reason;
|
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
|
|
|
}
|
|
|
|
|
2011-06-28 00:33:55 -04:00
|
|
|
void _alpm_conflict_free(alpm_conflict_t *conflict)
|
2008-01-11 01:01:58 -05:00
|
|
|
{
|
|
|
|
FREE(conflict->package2);
|
|
|
|
FREE(conflict->package1);
|
|
|
|
FREE(conflict);
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
|
2008-01-25 15:31:20 -05:00
|
|
|
{
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *newconflict;
|
2011-06-28 18:46:04 -04:00
|
|
|
CALLOC(newconflict, 1, sizeof(alpm_conflict_t), return NULL);
|
2008-01-25 15:31:20 -05:00
|
|
|
|
2011-08-09 00:25:45 -04:00
|
|
|
newconflict->package1_hash = conflict->package1_hash;
|
|
|
|
newconflict->package2_hash = conflict->package2_hash;
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newconflict->package1, conflict->package1, return NULL);
|
|
|
|
STRDUP(newconflict->package2, conflict->package2, return NULL);
|
2011-08-09 02:00:16 -04:00
|
|
|
newconflict->reason = conflict->reason;
|
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-06-28 00:33:55 -04:00
|
|
|
static int conflict_isin(alpm_conflict_t *needle, alpm_list_t *haystack)
|
2007-11-18 08:25:43 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = haystack; i; i = i->next) {
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *conflict = i->data;
|
2011-08-09 00:25:45 -04:00
|
|
|
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) {
|
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-28 00:04:00 -04:00
|
|
|
static int add_conflict(alpm_handle_t *handle, alpm_list_t **baddeps,
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_pkg_t *pkg1, alpm_pkg_t *pkg2, alpm_depend_t *reason)
|
2007-03-03 03:13:59 -05:00
|
|
|
{
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *conflict = conflict_new(pkg1, pkg2, reason);
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!conflict) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!conflict_isin(conflict, *baddeps)) {
|
2011-08-09 02:00:16 -04:00
|
|
|
char *conflict_str = alpm_dep_compute_string(reason);
|
2007-11-18 08:25:43 -05:00
|
|
|
*baddeps = alpm_list_add(*baddeps, conflict);
|
2011-08-09 02:00:16 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
|
|
|
|
pkg1->name, pkg2->name, conflict_str);
|
|
|
|
free(conflict_str);
|
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-28 00:04:00 -04:00
|
|
|
static void check_conflict(alpm_handle_t *handle,
|
2011-06-07 17:13:58 -04:00
|
|
|
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) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg1 = i->data;
|
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) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *conflict = j->data;
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *k;
|
2007-03-03 03:13:59 -05:00
|
|
|
|
2007-07-19 19:22:45 -04:00
|
|
|
for(k = list2; k; k = k->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg2 = k->data;
|
2007-07-19 19:22:45 -04:00
|
|
|
|
2011-08-09 00:25:45 -04:00
|
|
|
if(pkg1->name_hash == pkg2->name_hash
|
|
|
|
&& strcmp(pkg1->name, pkg2->name) == 0) {
|
2007-07-19 19:22:45 -04:00
|
|
|
/* skip the package we're currently processing */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-08-09 02:00:16 -04:00
|
|
|
if(_alpm_depcmp(pkg2, conflict)) {
|
2007-07-19 19:22:45 -04:00
|
|
|
if(order >= 0) {
|
2011-08-09 00:25:45 -04:00
|
|
|
add_conflict(handle, baddeps, pkg1, pkg2, conflict);
|
2007-07-19 19:22:45 -04:00
|
|
|
} else {
|
2011-08-09 00:25:45 -04:00
|
|
|
add_conflict(handle, baddeps, pkg2, pkg1, conflict);
|
2007-07-19 19:22:45 -04:00
|
|
|
}
|
|
|
|
}
|
2006-02-21 18:55:59 -05:00
|
|
|
}
|
2007-03-03 03:13:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 03:57:38 -05:00
|
|
|
/* Check for inter-conflicts */
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_list_t *_alpm_innerconflicts(alpm_handle_t *handle, alpm_list_t *packages)
|
2007-11-20 03:57:38 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *baddeps = NULL;
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "check targets vs targets\n");
|
2011-06-07 17:13:58 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-30 08:01:13 -04:00
|
|
|
/* Check for target vs (db - target) conflicts */
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t *_alpm_outerconflicts(alpm_db_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-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "check targets vs db\n");
|
2011-06-07 17:13:58 -04:00
|
|
|
check_conflict(db->handle, packages, dblist, &baddeps, 1);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "check db vs targets\n");
|
2011-06-07 17:13:58 -04:00
|
|
|
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
|
2011-06-28 00:33:55 -04:00
|
|
|
* @return an alpm_list_t of alpm_conflict_t
|
2007-12-09 08:49:34 -05:00
|
|
|
*/
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_checkconflicts(alpm_handle_t *handle,
|
2011-06-07 17:13:58 -04:00
|
|
|
alpm_list_t *pkglist)
|
|
|
|
{
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return NULL);
|
2011-06-07 14:53:53 -04:00
|
|
|
return _alpm_innerconflicts(handle, pkglist);
|
2007-11-20 03:57:38 -05:00
|
|
|
}
|
|
|
|
|
2011-09-26 18:31:34 -04:00
|
|
|
/* Adds alpm_fileconflict_t to a conflicts list. Pass the conflicts list, the
|
|
|
|
* conflicting file path, and either two packages or one package and NULL.
|
2007-02-13 23:52:17 -05:00
|
|
|
*/
|
2011-06-28 00:04:00 -04:00
|
|
|
static alpm_list_t *add_fileconflict(alpm_handle_t *handle,
|
2011-09-26 18:31:34 -04:00
|
|
|
alpm_list_t *conflicts, const char *filestr,
|
|
|
|
alpm_pkg_t *pkg1, alpm_pkg_t *pkg2)
|
2007-02-13 23:52:17 -05:00
|
|
|
{
|
2011-06-28 00:35:17 -04:00
|
|
|
alpm_fileconflict_t *conflict;
|
|
|
|
MALLOC(conflict, sizeof(alpm_fileconflict_t), goto error);
|
2007-10-29 02:00:52 -04:00
|
|
|
|
2011-09-26 18:31:34 -04:00
|
|
|
STRDUP(conflict->target, pkg1->name, goto error);
|
2011-06-14 10:30:46 -04:00
|
|
|
STRDUP(conflict->file, filestr, goto error);
|
2011-09-26 18:31:34 -04:00
|
|
|
if(pkg2) {
|
|
|
|
conflict->type = ALPM_FILECONFLICT_TARGET;
|
|
|
|
STRDUP(conflict->ctarget, pkg2->name, goto error);
|
2007-02-18 22:18:59 -05:00
|
|
|
} else {
|
2011-09-26 18:31:34 -04:00
|
|
|
conflict->type = ALPM_FILECONFLICT_FILESYSTEM;
|
2011-06-14 10:30:46 -04:00
|
|
|
STRDUP(conflict->ctarget, "", goto error);
|
2007-02-18 22:18:59 -05:00
|
|
|
}
|
|
|
|
|
2007-02-13 23:52:17 -05:00
|
|
|
conflicts = alpm_list_add(conflicts, conflict);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
|
2011-09-26 18:31:34 -04:00
|
|
|
filestr, pkg1->name, pkg2 ? pkg2->name : "(filesystem)");
|
2007-02-13 23:52:17 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return conflicts;
|
2011-06-14 10:30:46 -04:00
|
|
|
|
|
|
|
error:
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_MEMORY, conflicts);
|
2007-02-13 23:52:17 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:35:17 -04:00
|
|
|
void _alpm_fileconflict_free(alpm_fileconflict_t *conflict)
|
2008-01-11 01:01:58 -05:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-08 07:36:36 -04:00
|
|
|
static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath,
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg)
|
2009-07-17 09:48:57 -04:00
|
|
|
{
|
2012-07-08 07:36:36 -04:00
|
|
|
alpm_list_t *i;
|
2009-07-17 09:48:57 -04:00
|
|
|
struct stat sbuf;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char abspath[PATH_MAX];
|
|
|
|
DIR *dir;
|
2012-07-08 07:36:36 -04:00
|
|
|
struct dirent *ent = NULL;
|
|
|
|
const char *root = handle->root;
|
|
|
|
|
2012-07-08 09:58:37 -04:00
|
|
|
/* check directory is actually in package - used for subdirectory checks */
|
2012-07-12 16:29:59 -04:00
|
|
|
if(!alpm_filelist_contains(alpm_pkg_get_files(pkg), dirpath)) {
|
2012-07-10 21:16:37 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"directory %s not in package %s\n", dirpath, pkg->name);
|
2012-07-08 09:58:37 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-08 07:36:36 -04:00
|
|
|
/* TODO: this is an overly strict check but currently pacman will not
|
|
|
|
* overwrite a directory with a file (case 10/11 in add.c). Adjusting that
|
|
|
|
* is not simple as even if the directory is being unowned by a conflicting
|
|
|
|
* package, pacman does not sort this to ensure all required directory
|
|
|
|
* "removals" happen before installation of file/symlink */
|
|
|
|
|
|
|
|
/* check that no other _installed_ package owns the directory */
|
|
|
|
for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) {
|
|
|
|
if(pkg == i->data) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-12 16:29:59 -04:00
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(i->data), dirpath)) {
|
2012-07-10 21:16:37 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"file %s also in package %s\n", dirpath,
|
|
|
|
((alpm_pkg_t*)i->data)->name);
|
2012-07-08 07:36:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 09:48:57 -04:00
|
|
|
|
2012-07-08 07:36:36 -04:00
|
|
|
/* check all files in directory are owned by the package */
|
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
|
|
|
}
|
2011-06-16 14:16:49 -04:00
|
|
|
|
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;
|
|
|
|
}
|
2012-07-08 07:36:36 -04:00
|
|
|
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)) {
|
2012-07-08 07:36:36 -04:00
|
|
|
if(dir_belongsto_pkg(handle, 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 {
|
2012-07-12 16:29:59 -04:00
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(pkg), path)) {
|
2009-07-17 09:48:57 -04:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
closedir(dir);
|
2012-07-10 21:16:37 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"unowned file %s found in directory\n", path);
|
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-28 00:04:00 -04:00
|
|
|
alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
2012-05-08 17:23:58 -04:00
|
|
|
alpm_list_t *upgrade, alpm_list_t *rem)
|
2005-03-22 15:21:12 -05:00
|
|
|
{
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_list_t *i, *conflicts = NULL;
|
2010-12-08 00:13:36 -05:00
|
|
|
size_t numtargs = alpm_list_count(upgrade);
|
|
|
|
size_t current;
|
2011-12-12 14:05:10 -05:00
|
|
|
size_t rootlen;
|
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
|
|
|
|
2011-12-12 14:05:10 -05:00
|
|
|
rootlen = strlen(handle->root);
|
|
|
|
|
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++) {
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_pkg_t *p1 = i->data;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_list_t *j;
|
|
|
|
alpm_filelist_t tmpfiles;
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_pkg_t *dbpkg;
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
size_t filenum;
|
2007-02-21 23:42:59 -05:00
|
|
|
|
2011-01-09 21:36:42 -05:00
|
|
|
int percent = (current * 100) / numtargs;
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_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-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "searching for file conflicts: %s\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
p1->name);
|
2007-02-13 03:15:38 -05:00
|
|
|
for(j = i->next; j; j = j->next) {
|
2011-06-14 10:30:46 -04:00
|
|
|
alpm_list_t *common_files;
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_pkg_t *p2 = j->data;
|
2012-07-17 22:09:24 -04:00
|
|
|
common_files = _alpm_filelist_intersection(alpm_pkg_get_files(p1),
|
|
|
|
alpm_pkg_get_files(p2));
|
2007-02-13 03:15:38 -05:00
|
|
|
|
2011-06-14 10:30:46 -04:00
|
|
|
if(common_files) {
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_list_t *k;
|
|
|
|
char path[PATH_MAX];
|
2011-06-14 10:30:46 -04:00
|
|
|
for(k = common_files; k; k = k->next) {
|
2011-09-26 18:31:34 -04:00
|
|
|
alpm_file_t *file = k->data;
|
|
|
|
snprintf(path, PATH_MAX, "%s%s", handle->root, file->name);
|
|
|
|
conflicts = add_fileconflict(handle, conflicts, path, p1, p2);
|
2011-07-01 12:01:39 -04:00
|
|
|
if(handle->pm_errno == ALPM_ERR_MEMORY) {
|
2011-06-07 17:06:16 -04:00
|
|
|
FREELIST(conflicts);
|
2011-06-14 10:30:46 -04:00
|
|
|
FREELIST(common_files);
|
|
|
|
return NULL;
|
2011-06-07 17:06:16 -04:00
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2011-06-16 14:16:49 -04:00
|
|
|
alpm_list_free(common_files);
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-15 19:31:21 -04:00
|
|
|
/* CHECK 2: check every target against the filesystem */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "searching for filesystem conflicts: %s\n",
|
2011-06-14 10:30:46 -04:00
|
|
|
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
|
2011-06-14 10:30:46 -04:00
|
|
|
* is not currently installed, then simply stat the whole filelist. Note
|
|
|
|
* that the former list needs to be freed while the latter list should NOT
|
|
|
|
* be freed. */
|
2007-02-13 23:52:17 -05:00
|
|
|
if(dbpkg) {
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
alpm_list_t *difference;
|
2007-02-13 23:52:17 -05:00
|
|
|
/* older ver of package currently installed */
|
2012-07-17 22:09:24 -04:00
|
|
|
difference = _alpm_filelist_difference(alpm_pkg_get_files(p1),
|
|
|
|
alpm_pkg_get_files(dbpkg));
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
tmpfiles.count = alpm_list_count(difference);
|
|
|
|
tmpfiles.files = alpm_list_to_array(difference, tmpfiles.count,
|
|
|
|
sizeof(alpm_file_t));
|
|
|
|
alpm_list_free(difference);
|
2007-02-13 23:52:17 -05:00
|
|
|
} else {
|
|
|
|
/* no version of package currently installed */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
tmpfiles = *alpm_pkg_get_files(p1);
|
2007-02-19 21:14:27 -05:00
|
|
|
}
|
2007-02-13 23:52:17 -05:00
|
|
|
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
for(filenum = 0; filenum < tmpfiles.count; filenum++) {
|
|
|
|
alpm_file_t *file = tmpfiles.files + filenum;
|
2011-06-16 14:16:49 -04:00
|
|
|
const char *filestr = file->name;
|
|
|
|
const char *relative_path;
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_list_t *k;
|
2011-06-27 10:07:06 -04:00
|
|
|
/* have we acted on this conflict? */
|
|
|
|
int resolved_conflict = 0;
|
2011-06-16 16:40:02 -04:00
|
|
|
struct stat lsbuf;
|
|
|
|
char path[PATH_MAX];
|
2011-11-13 18:19:28 -05:00
|
|
|
size_t pathlen;
|
2007-02-19 21:14:27 -05:00
|
|
|
|
2011-11-13 18:19:28 -05:00
|
|
|
pathlen = 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
|
|
|
|
2011-10-26 18:32:46 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking possible conflict: %s\n", path);
|
|
|
|
|
2011-06-16 16:40:02 -04:00
|
|
|
if(S_ISDIR(file->mode)) {
|
2011-06-14 10:30:46 -04:00
|
|
|
struct stat sbuf;
|
2008-01-06 04:59:41 -05:00
|
|
|
if(S_ISDIR(lsbuf.st_mode)) {
|
2011-10-26 18:32:46 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "file is a directory, not a conflict\n");
|
2009-01-02 11:43:05 -05:00
|
|
|
continue;
|
2011-06-14 10:30:46 -04:00
|
|
|
}
|
|
|
|
stat(path, &sbuf);
|
|
|
|
if(S_ISLNK(lsbuf.st_mode) && S_ISDIR(sbuf.st_mode)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-10-26 18:32:46 -04:00
|
|
|
"file is a symlink to a dir, hopefully not a conflict\n");
|
2009-01-02 11:43:05 -05:00
|
|
|
continue;
|
2008-01-06 04:59:41 -05:00
|
|
|
}
|
2011-06-27 10:07:06 -04:00
|
|
|
/* if we made it to here, we want all subsequent path comparisons to
|
|
|
|
* not include the trailing slash. This allows things like file ->
|
|
|
|
* directory replacements. */
|
2011-11-13 18:19:28 -05:00
|
|
|
path[pathlen - 1] = '\0';
|
2008-01-06 04:59:41 -05:00
|
|
|
}
|
2007-02-21 23:42:59 -05:00
|
|
|
|
2011-12-12 14:05:10 -05:00
|
|
|
relative_path = path + rootlen;
|
2009-01-02 11:43:05 -05:00
|
|
|
|
|
|
|
/* Check remove list (will we remove the conflicting local file?) */
|
2012-05-08 17:23:58 -04:00
|
|
|
for(k = rem; k && !resolved_conflict; k = k->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *rempkg = k->data;
|
2012-07-12 16:29:59 -04:00
|
|
|
if(rempkg && alpm_filelist_contains(alpm_pkg_get_files(rempkg),
|
2011-06-16 14:16:49 -04:00
|
|
|
relative_path)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-10-26 18:32:46 -04:00
|
|
|
"local file will be removed, not a conflict\n");
|
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) {
|
2011-06-16 16:40:02 -04:00
|
|
|
alpm_pkg_t *p2 = k->data;
|
2009-01-02 11:43:05 -05:00
|
|
|
if(!p2 || strcmp(p1->name, p2->name) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_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) */
|
2012-07-12 16:29:59 -04:00
|
|
|
if(localp2 && alpm_filelist_contains(alpm_pkg_get_files(localp2), filestr)) {
|
2009-01-02 11:43:05 -05:00
|
|
|
/* 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-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-10-26 18:32:46 -04:00
|
|
|
"file changed packages, adding to remove skiplist\n");
|
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);
|
2012-07-12 16:29:59 -04:00
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(dbpkg), dir)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2012-07-10 21:16:37 -04:00
|
|
|
"checking if all files in %s belong to %s\n",
|
2009-07-17 09:48:57 -04:00
|
|
|
dir, dbpkg->name);
|
2012-07-08 07:36:36 -04:00
|
|
|
resolved_conflict = dir_belongsto_pkg(handle, dir, dbpkg);
|
2009-07-17 09:48:57 -04:00
|
|
|
}
|
|
|
|
free(dir);
|
|
|
|
}
|
|
|
|
|
2011-10-26 18:32:46 -04:00
|
|
|
/* check if a component of the filepath was a link. canonicalize the path
|
|
|
|
* and look for it in the old package. note that the actual file under
|
|
|
|
* consideration cannot itself be a link, as it might be unowned- path
|
|
|
|
* components can be safely checked as all directories are "unowned". */
|
|
|
|
if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) {
|
2012-04-29 21:14:10 -04:00
|
|
|
char rpath[PATH_MAX];
|
2011-10-26 18:32:46 -04:00
|
|
|
if(realpath(path, rpath)) {
|
2011-12-12 14:05:10 -05:00
|
|
|
const char *relative_rpath = rpath + rootlen;
|
2012-07-12 16:29:59 -04:00
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) {
|
2011-10-26 18:32:46 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"package contained the resolved realpath\n");
|
|
|
|
resolved_conflict = 1;
|
|
|
|
}
|
2009-07-19 10:54:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 16:32:03 -04:00
|
|
|
/* is the file unowned and in the backup list of the new package? */
|
|
|
|
if(!resolved_conflict && _alpm_needbackup(filestr, p1)) {
|
|
|
|
alpm_list_t *local_pkgs = _alpm_db_get_pkgcache(handle->db_local);
|
|
|
|
int found = 0;
|
|
|
|
for(k = local_pkgs; k && !found; k = k->next) {
|
2012-07-12 16:29:59 -04:00
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(k->data), filestr)) {
|
2011-07-14 16:32:03 -04:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2011-10-26 18:32:46 -04:00
|
|
|
"file was unowned but in new backup list\n");
|
2011-07-14 16:32:03 -04:00
|
|
|
resolved_conflict = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
if(!resolved_conflict) {
|
2011-09-26 18:31:34 -04:00
|
|
|
conflicts = add_fileconflict(handle, conflicts, path, p1, NULL);
|
2011-07-01 12:01:39 -04:00
|
|
|
if(handle->pm_errno == ALPM_ERR_MEMORY) {
|
2011-06-07 17:06:16 -04:00
|
|
|
FREELIST(conflicts);
|
2011-06-14 10:30:46 -04:00
|
|
|
if(dbpkg) {
|
2012-07-17 22:09:24 -04:00
|
|
|
/* only freed if it was generated from _alpm_filelist_difference() */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
free(tmpfiles.files);
|
2011-06-14 10:30:46 -04:00
|
|
|
}
|
|
|
|
return NULL;
|
2011-06-07 17:06:16 -04:00
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2011-06-14 10:30:46 -04:00
|
|
|
if(dbpkg) {
|
2012-07-17 22:09:24 -04:00
|
|
|
/* only freed if it was generated from _alpm_filelist_difference() */
|
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change.
1. Iteration is much more performant, due to a reduction in pointer
chasing and linear item access.
2. Data structures are smaller- we no longer have the overhead of the
linked list as the file struts are now laid out consecutively in
memory.
3. Memory allocation has been massively reworked. Before, we would
allocate three different pieces of memory per file item- the list
struct, the file struct, and the copied filename. What this resulted
in was massive fragmentation of memory when loading filelists since
the memory allocator had to leave holes all over the place. The new
situation here now removes the need for any list item allocation;
allocates the file structs in contiguous memory (and reallocs as
necessary), leaving only the strings as individually allocated. Tests
using valgrind (massif) show some pretty significant memory
reductions on the worst case `pacman -Ql > /dev/null` (366387 files
on my machine):
Before:
Peak heap: 54,416,024 B
Useful heap: 36,840,692 B
Extra heap: 17,575,332 B
After:
Peak heap: 38,004,352 B
Useful heap: 28,101,347 B
Extra heap: 9,903,005 B
Several small helper methods have been introduced, including a list to
array conversion helper as well as a filelist merge sort that works
directly on arrays.
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-07-19 05:47:29 -04:00
|
|
|
free(tmpfiles.files);
|
2011-06-14 10:30:46 -04:00
|
|
|
}
|
2005-03-22 15:21:12 -05:00
|
|
|
}
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_CONFLICTS_START, "", 100,
|
2011-02-08 22:16:04 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|