Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: NO_CASE_GLOB and unreadable directories (Episode VI: A New Hope)



No comment on this at all?  Some additional remarks below.

On Wed, Jan 13, 2021 at 9:57 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Effectively, NO_CASE_GLOB turns the pure path
>   /data/data/com.termux/files/home
> (to stick with the original example) into the extendedglob pattern
>   /(#i)data/(#i)data/(#i)com.termux/(#i)files/(#i)home
> which means every component has to be compared with pattry() rather
> than as a literal string.  That in turn means that every parent must
> be readable.

There's no practical workaround for this that I can see.  Without
reading the parent directory, on a case-sensitive filesystem we'd have
to attempt to chdir to every possible combination of upper/lower case
in the pathname.

> It further means that
>   anydir/*
> becomes
>   (#i)anydir/(#i)*
> which could be construed as incorrect, because if there are two directories
>   AnyDir/
>   anydir/
> that pattern will return everything in both of them

I think this is a real bug, but it can't be fixed without breaking the
case in which the current implementation finds AnyDir/ in the absence
of anydir/ (assuming the parent of AnyDir is readable).

> What's wanted in Devin's case is for (#i) to apply exactly when there
> are other pattern characters in the component, e.g.,
>   (#I)anydir/(#i)*

This is probably how CASEGLOB should have been implemented in the
first place.  Note that the documentation sort of implies this
interpretation:

     [nocaseglob] the presence of any character which is special to
     filename generation will cause case-insensitive matching.  For
     example, cvs(/) can match the directory CVS owing to the presence
     of the globbing flag (unless the option BARE_GLOB_QUAL is unset).

There's no mention in there of what happens when the path is more than
one directory deep.

I see these possibilities:
1) Do nothing; Devin's case is broken by design and termux needs to
come up with a solution that doesn't involve NO_CASE_GLOB.
2) Adopt (a CYGWIN-clean variant of) my patch from workers/47832, and
accept that some current usage of NO_CASE_GLOB will break.
3) Add a setopt (CASE_DIRS ?) for the current behavior, and merge that
with workers/47832.  I haven't yet worked out how to avoid having
"setopt nocasedirs" imply the effects of "setopt nocaseglob" ...
perhaps name it CASE_SEARCH (?) and simply leave the implication?




Messages sorted by: Reverse Date, Date, Thread, Author