mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
query_fileowner: remove resolve_path function
resolve_path is a equivalent to calling realpath(path, NULL) except that the returned string is guaranteed to be PATH_MAX long. We never append to the returned string, so this is unnecessary. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
bad00696f3
commit
9648887481
@ -38,23 +38,6 @@
|
|||||||
|
|
||||||
#define LOCAL_PREFIX "local/"
|
#define LOCAL_PREFIX "local/"
|
||||||
|
|
||||||
static char *resolve_path(const char *file)
|
|
||||||
{
|
|
||||||
char *str = NULL;
|
|
||||||
|
|
||||||
str = calloc(PATH_MAX, sizeof(char));
|
|
||||||
if(!str) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!realpath(file, str)) {
|
|
||||||
free(str);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if filename exists in PATH */
|
/* check if filename exists in PATH */
|
||||||
static int search_path(char **filename, struct stat *bufptr)
|
static int search_path(char **filename, struct stat *bufptr)
|
||||||
{
|
{
|
||||||
@ -178,7 +161,7 @@ static int query_fileowner(alpm_list_t *targets)
|
|||||||
if(strcmp(dname, "") == 0) {
|
if(strcmp(dname, "") == 0) {
|
||||||
rpath = NULL;
|
rpath = NULL;
|
||||||
} else {
|
} else {
|
||||||
rpath = resolve_path(dname);
|
rpath = realpath(dname, NULL);
|
||||||
|
|
||||||
if(!rpath) {
|
if(!rpath) {
|
||||||
pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
|
pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
|
||||||
@ -202,7 +185,7 @@ static int query_fileowner(alpm_list_t *targets)
|
|||||||
char *ppath, *pdname;
|
char *ppath, *pdname;
|
||||||
const char *pkgfile = file->name;
|
const char *pkgfile = file->name;
|
||||||
|
|
||||||
/* avoid the costly resolve_path usage if the basenames don't match */
|
/* avoid the costly realpath usage if the basenames don't match */
|
||||||
if(strcmp(mbasename(pkgfile), bname) != 0) {
|
if(strcmp(mbasename(pkgfile), bname) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -225,7 +208,7 @@ static int query_fileowner(alpm_list_t *targets)
|
|||||||
strcpy(path + rootlen, pkgfile);
|
strcpy(path + rootlen, pkgfile);
|
||||||
|
|
||||||
pdname = mdirname(path);
|
pdname = mdirname(path);
|
||||||
ppath = resolve_path(pdname);
|
ppath = realpath(pdname, NULL);
|
||||||
free(pdname);
|
free(pdname);
|
||||||
|
|
||||||
if(ppath && strcmp(ppath, rpath) == 0) {
|
if(ppath && strcmp(ppath, rpath) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user