This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] posix: if glob has a trailing slash match directories only.
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Dmitry Goncharov <dgoncharov at users dot sf dot net>, libc-alpha at sourceware dot org
- Date: Tue, 28 Nov 2017 22:35:40 -0800
- Subject: Re: [PATCH] posix: if glob has a trailing slash match directories only.
- Authentication-results: sourceware.org; auth=none
- References: <20171128210857.GC2745@madrid> <a97c9749-5bcd-0292-9eae-bd7c4c59ab09@cs.ucla.edu> <20171129042114.GA2702@madrid>
Dmitry Goncharov wrote:
Author: Ulrich Drepper<drepper@redhat.com>
Date: Fri Oct 31 22:55:02 1997 +0000
Ah, so this is a longstanding bug in glob, and was not introduced by the recent
merge from Gnulib. That's a relief.
As long as your filesystem initializes d->d_type you won't see the issue.
When d->d_type is DT_UNKNOWN then d may not be a directory.
Thanks for clarifying. Now that I understand it better, though, I still see a
problem. As noted in the Glibc manual here:
https://www.gnu.org/software/libc/manual/html_node/More-Flags-for-Globbing.html#index-GLOB_005fONLYDIR
GLOB_ONLYDIR is merely an efficiency flag: it means "do not return entries that
can easily be shown to be non-directories". Your patch would change the
semantics of GLOB_ONLYDIR so that it means "return only entries that are known
to be directories", which differs from the Glibc documentation.
The bug here is not in the implementation of GLOB_ONLYDIR; it is in the part of
glob that calls itself recursively with GLOB_ONLYDIR, and which expects only
directories (or symlinks to directories) to be matched.
This issue came up in September, here:
https://sourceware.org/ml/libc-alpha/2017-09/msg00888.html