This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] posix: if glob has a trailing slash match directories only.
- From: Dmitry Goncharov <dgoncharov at users dot sf dot net>
- To: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: libc-alpha at sourceware dot org, bug-gnulib at gnu dot org
- Date: Mon, 4 Dec 2017 10:46:23 -0500
- Subject: Re: [PATCH] posix: if glob has a trailing slash match directories only.
- Authentication-results: sourceware.org; auth=none
- References: <20171128210857.GC2745@madrid> <firstname.lastname@example.org> <20171129042114.GA2702@madrid> <email@example.com> <CAG+Z0CsgP0sMTtaurAF8kXJ0HSqhPMC-BxS36=OB05GNUo9xSQ@mail.gmail.com> <CAG+Z0CsvFWv+JGauq3=PAV8=pcD9YHi8p1k9yTbsdT8iNU9AZw@mail.gmail.com> <firstname.lastname@example.org> <20171204042021.GA3045@madrid> <email@example.com>
On Mon, Dec 4, 2017 at 3:01 AM, Paul Eggert <firstname.lastname@example.org> wrote:
> Dmitry Goncharov wrote:
>>> flags |= GLOB_ONLYDIR | GLOB_MARK;
>>> and then at the end, filter out all matches that aren't marked with
>>> trailing '/'. This would avoid creating a new GLOB_XXX option and would
>>> probably be easier to implement.
>> Please have a look at this implementation of your idea.
> I'm not quite following how it's an implementation, since I don't see where
> it does anything like "flags |= GLOB_ONLYDIR | GLOB_MARK;". Maybe there's
> another part of the patch you're missing?
glob sets GLOB_MARK when it calls itself recursively when the pattern
has a trailing slash.
> The variable "filter" is a boolean and should be of type bool.
> That comment and code look over-complicated.
i agree. Will remove the comment.
> Can't you simply copy nonnull entries in-place, in a single pass?
The first pass calls is_dir and frees and resets files. Do you mean to
also do copying in this very pass?
> That way, the filtered order will be the same as the original order.
The stable algorithm results in more iterations and more copying. Are you sure?