From d5a0f1178fb64a6b3759c1e685d3c0074406c6ff Mon Sep 17 00:00:00 2001 From: joerg Date: Fri, 20 Jun 2008 08:39:42 +0000 Subject: [PATCH] Make the search for sources in PATH_PORTS more accurate. I only noticed that a "whereis -qs qemu" matched the distfiles subdir of qemu rather than /usr/ports/emulators/qemu. It now ignores all dot entries in /usr/ports, plus all entries starting with a capital letter (maintenance stuff like Templates, but also includes subdir CVS), plus /usr/ports/distfiles which is simply a magic name in that respect. --- usr.bin/whereis/whereis.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c index 70feb8a3eaaa..0829f77037b0 100644 --- a/usr.bin/whereis/whereis.c +++ b/usr.bin/whereis/whereis.c @@ -329,9 +329,28 @@ defaults(void) if ((dir = opendir(PATH_PORTS)) == NULL) err(EX_OSERR, "opendir" PATH_PORTS ")"); while ((dirp = readdir(dir)) != NULL) { + /* + * Not everything below PATH_PORTS is of + * interest. First, all dot files and + * directories (e. g. .snap) can be ignored. + * Also, all subdirectories starting with a + * capital letter are not going to be + * examined, as they are used for internal + * purposes (Mk, Tools, ...). This also + * matches a possible CVS subdirectory. + * Finally, the distfiles subdirectory is also + * special, and should not be considered to + * avoid false matches. + */ if (dirp->d_name[0] == '.' || - strcmp(dirp->d_name, "CVS") == 0) - /* ignore dot entries and CVS subdir */ + /* + * isupper() not used on purpose: the + * check is supposed to default to the C + * locale instead of the current user's + * locale. + */ + (dirp->d_name[0] >= 'A' && dirp->d_name[0] <= 'Z') || + strcmp(dirp->d_name, "distfiles") == 0) continue; if ((b = malloc(sizeof PATH_PORTS + 1 + dirp->d_namlen)) == NULL)