index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | lib/libalpm/conflict.c | 41 |
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 6bfd256f..60691c94 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -1,7 +1,7 @@ /* * conflict.c * - * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> * Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org> @@ -22,8 +22,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "config.h" - #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -317,15 +315,16 @@ void _alpm_fileconflict_free(alpm_fileconflict_t *conflict) const alpm_file_t *_alpm_filelist_contains(alpm_filelist_t *filelist, const char *name) { - size_t i; - const alpm_file_t *file = filelist->files; - for(i = 0; i < filelist->count; i++) { - if(strcmp(file->name, name) == 0) { - return file; - } - file++; + alpm_file_t key; + + if(!filelist) { + return NULL; } - return NULL; + + key.name = (char *)name; + + return bsearch(&key, filelist->files, filelist->count, + sizeof(alpm_file_t), _alpm_files_cmp); } static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath, @@ -410,16 +409,19 @@ static int dir_belongsto_pkg(alpm_handle_t *handle, const char *dirpath, * 1: check every target against every target * 2: check every target against the filesystem */ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, - alpm_list_t *upgrade, alpm_list_t *remove) + alpm_list_t *upgrade, alpm_list_t *rem) { alpm_list_t *i, *conflicts = NULL; size_t numtargs = alpm_list_count(upgrade); size_t current; + size_t rootlen; if(!upgrade) { return NULL; } + rootlen = strlen(handle->root); + /* 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 @@ -493,8 +495,9 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, int resolved_conflict = 0; struct stat lsbuf; char path[PATH_MAX]; + size_t pathlen; - snprintf(path, PATH_MAX, "%s%s", handle->root, filestr); + pathlen = snprintf(path, PATH_MAX, "%s%s", handle->root, filestr); /* stat the file - if it exists, do some checks */ if(_alpm_lstat(path, &lsbuf) != 0) { @@ -518,13 +521,13 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, /* 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. */ - path[strlen(path) - 1] = '\0'; + path[pathlen - 1] = '\0'; } - relative_path = path + strlen(handle->root); + relative_path = path + rootlen; /* Check remove list (will we remove the conflicting local file?) */ - for(k = remove; k && !resolved_conflict; k = k->next) { + for(k = rem; k && !resolved_conflict; k = k->next) { alpm_pkg_t *rempkg = k->data; if(rempkg && _alpm_filelist_contains(alpm_pkg_get_files(rempkg), relative_path)) { @@ -573,17 +576,15 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, * 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)) { - char *rpath = calloc(PATH_MAX, sizeof(char)); - const char *relative_rpath; + char rpath[PATH_MAX]; if(realpath(path, rpath)) { - relative_rpath = rpath + strlen(handle->root); + const char *relative_rpath = rpath + rootlen; if(_alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) { _alpm_log(handle, ALPM_LOG_DEBUG, "package contained the resolved realpath\n"); resolved_conflict = 1; } } - free(rpath); } /* is the file unowned and in the backup list of the new package? */ |