query_fileowner: remove assumption that root is "/"

Returning "/" from mdirname removes it as a special case which allows us to
test it like any other directory.  This corrects a false positive when querying
a file in / and root is not set to /.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
Andrew Gregory 2012-08-11 17:35:12 -04:00 committed by Dan McGee
parent 03f2e2360a
commit de7a5cf346
2 changed files with 11 additions and 25 deletions

View file

@ -173,21 +173,12 @@ static int query_fileowner(alpm_list_t *targets)
bname = mbasename(filename); bname = mbasename(filename);
dname = mdirname(filename); dname = mdirname(filename);
/* for files in '/', there is no directory name to match */
if(strcmp(dname, "") == 0) {
rpath = NULL;
} else {
rpath = realpath(dname, NULL); rpath = realpath(dname, NULL);
if(!rpath) { if(!dname || !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"),
filename, strerror(errno)); filename, strerror(errno));
free(filename); goto targcleanup;
free(dname);
free(rpath);
ret++;
continue;
}
} }
free(dname); free(dname);
@ -206,21 +197,11 @@ static int query_fileowner(alpm_list_t *targets)
continue; continue;
} }
/* for files in '/', there is no directory name to match */ /* concatenate our file and the root path */
if(!rpath) {
if(strcmp(pkgfile, bname) == 0) {
print_query_fileowner(filename, info);
found = 1;
break;
}
continue;
}
if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) { if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), path, pkgfile); pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), path, pkgfile);
continue; continue;
} }
/* concatenate our file and the root path */
strcpy(path + rootlen, pkgfile); strcpy(path + rootlen, pkgfile);
pdname = mdirname(path); pdname = mdirname(path);

View file

@ -244,9 +244,14 @@ char *mdirname(const char *path)
if(last != NULL) { if(last != NULL) {
/* we found a '/', so terminate our string */ /* we found a '/', so terminate our string */
if(last == ret) {
/* return "/" for root */
last++;
}
*last = '\0'; *last = '\0';
return ret; return ret;
} }
/* no slash found */ /* no slash found */
free(ret); free(ret);
return strdup("."); return strdup(".");