1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

File conflict code cleanups

While researching the root cause of FS#24904, I couldn't help but clean
up some of the cruft in here. A few whitespace/line-wrapping issues, but
also fix shadowed variables and add some const where applicable.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-27 09:02:01 -05:00
parent 6eee3f6781
commit f8f4c2a6f3

View File

@ -296,14 +296,14 @@ static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
return(ret); return(ret);
} }
/* Adds pmfileconflict_t to a conflicts list. Pass the conflicts list, type (either /* Adds pmfileconflict_t to a conflicts list. Pass the conflicts list, type
* PM_FILECONFLICT_TARGET or PM_FILECONFLICT_FILESYSTEM), a file string, and either * (either PM_FILECONFLICT_TARGET or PM_FILECONFLICT_FILESYSTEM), a file
* two package names or one package name and NULL. This is a wrapper for former * string, and either two package names or one package name and NULL. This is
* functionality that was done inline. * a wrapper for former functionality that was done inline.
*/ */
static alpm_list_t *add_fileconflict(alpm_list_t *conflicts, static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
pmfileconflicttype_t type, const char *filestr, pmfileconflicttype_t type, const char *filestr,
const char* name1, const char* name2) const char *name1, const char *name2)
{ {
pmfileconflict_t *conflict; pmfileconflict_t *conflict;
MALLOC(conflict, sizeof(pmfileconflict_t), RET_ERR(PM_ERR_MEMORY, NULL)); MALLOC(conflict, sizeof(pmfileconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
@ -334,7 +334,7 @@ void _alpm_fileconflict_free(pmfileconflict_t *conflict)
FREE(conflict); FREE(conflict);
} }
static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg) static int dir_belongsto_pkg(const char *dirpath, pmpkg_t *pkg)
{ {
struct dirent *ent = NULL; struct dirent *ent = NULL;
struct stat sbuf; struct stat sbuf;
@ -462,7 +462,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
} }
stat(path, &sbuf); stat(path, &sbuf);
if(path[strlen(path)-1] == '/') { if(path[strlen(path) - 1] == '/') {
if(S_ISDIR(lsbuf.st_mode)) { if(S_ISDIR(lsbuf.st_mode)) {
_alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path); _alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path);
continue; continue;
@ -518,19 +518,19 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
if(!resolved_conflict && dbpkg) { if(!resolved_conflict && dbpkg) {
char *rpath = calloc(PATH_MAX+1, sizeof(char)); char *rpath = calloc(PATH_MAX+1, sizeof(char));
const char *relative_rpath;
if(!realpath(path, rpath)) { if(!realpath(path, rpath)) {
FREE(rpath); free(rpath);
continue; continue;
} }
char *filestr = rpath + strlen(handle->root); relative_rpath = rpath + strlen(handle->root);
if(alpm_list_find_str(alpm_pkg_get_files(dbpkg),filestr)) { if(alpm_list_find_str(alpm_pkg_get_files(dbpkg), relative_rpath)) {
resolved_conflict = 1; resolved_conflict = 1;
} }
free(rpath); free(rpath);
} }
if(!resolved_conflict) { if(!resolved_conflict) {
_alpm_log(PM_LOG_DEBUG, "file found in conflict: %s\n", path);
conflicts = add_fileconflict(conflicts, PM_FILECONFLICT_FILESYSTEM, conflicts = add_fileconflict(conflicts, PM_FILECONFLICT_FILESYSTEM,
path, p1->name, NULL); path, p1->name, NULL);
} }