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

Re: zsh expansion fails if nocaseglob and not all directory components are listable



Oliver Freyermuth wrote on Mon, 22 Aug 2022 18:02 +00:00:
> 1) Prepare directory:
>
> mkdir foo
> chmod 711 foo
> mkdir foo/test
> sudo chown root:root foo
> cd foo/test
⋮
> setopt nocaseglob
> echo $(pwd)(N)
>
> => No output is returned.
>

If the (N) is changed to (|) [that's an empty alternation], one gets
a "no matches found" error.

> Of course, zsh can not exclude there are other directories directly 
> inside "foo/" matching the given pattern (but with different case) 
> since "foo/" can not be listed. However, at least the explicit match 
> with case is known,
> so I'm astonished zero matches are returned.
>
> Is this expected, or a bug?

What would you have it do instead?

  Emit just one path?  I don't think this would work, because if the
  glob expands at all, users may rely on what it _didn't_ expand to.
  It's perfectly within the API promise for a user to set NO_CASE_GLOB
  and then rely on something along the lines of the lines of «if print -l
  /etc(|) | grep -q /ETC; then …» (note that grep(1) is case-sensitive
  in this case).

  For comparison, consider «*(u.jrandom.)» and assume a single file in
  the directory returned -1 from stat(2) (so owner uid isn't known).
  Would it be okay to just elide that file from the glob's expansion?

- Error out hard?  NULL_GLOB is typically used to mean "Treat a glob
  with zero matches the same way as any other glob", and this case is
  rather "We couldn't determine the number of matches", so, maybe?

- Enumerate all paths that compare case-insensitively equal to
  a different path and expand the glob as in the non-0711 case?  Even
  assuming ASCII English this is O(2**N) in the length of the path
  (e.g., "test" is length 4 and has 2**4 possibilities), so, not tractable.

Could be that I'm missing something, of course…

Daniel




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