summaryrefslogtreecommitdiff
path: root/lib/libalpm/conflict.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/conflict.c')
-rw-r--r--lib/libalpm/conflict.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 32f6f303..85429029 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>
@@ -318,12 +316,16 @@ 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++) {
+ const alpm_file_t *file;
+
+ if(!filelist) {
+ return NULL;
+ }
+
+ for(file = filelist->files, i = 0; i < filelist->count; file++, i++) {
if(strcmp(file->name, name) == 0) {
return file;
}
- file++;
}
return NULL;
}
@@ -383,11 +385,14 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
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
@@ -461,8 +466,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) {
@@ -486,10 +492,10 @@ 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) {
@@ -542,9 +548,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
* 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;
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");