zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: zsh-workers@zsh.org
Subject: Re: glob qualifier '-' doesn't work correctly on dangling symlinks
Date: Mon, 13 Apr 2020 15:22:57 +0100	[thread overview]
Message-ID: <20200413142257.orwzb4jrgmf7gpoi@chazelas.org> (raw)
In-Reply-To: <20200412233845.GB1831017@zira.vinc17.org>

2020-04-13 01:38:45 +0200, Vincent Lefevre:
[...]
> > Well, as seen in the varying interpretations made by the various
> > implementations, it is not that clear. How do you determine
> > whether a file exists or not? What does "exist" mean?
> 
> You necessarily know it, or that's an error case (permission denied
> or whatever). The behavior may not be clear in case of error, but
> one can expect at least a non-zero exit status:
[...]

Are you saying that EACCES is an "error" but ENOENT is not? How
about ENOTDIR, ELOOP? None of /etc/passwd/foo, /etc/pesswd/foo,
symloop/foo or /root/foo exist on my system, a stat() on a
symlink to those would return ENOTDIR, ENOENT, ELOOP, EACCES. On
which one should find -L return with a non-zero exit status?
Which one(s) should find -L . -type l (or find . -xtype l)
print?

[...]
>   -e  pathname
>     True if pathname resolves to an existing directory entry.
>     False if pathname cannot be resolved.
> 
> BTW, I don't know how zsh behaves on "[[ -e pathname ]]" in case of
> error other than ENOENT in the pathname resolution, but this should
> be documented (and ditto for the other conditional expressions).
[...]

The mention of "directory entry" is misleading here. It's really
about a "file" more than a "directory entry" as stat() gets you
to the inode.

Maybe:

 -e  pathname
   True if pathname can be determined to resolve to an existing
   file (of any type). False otherwise. Note that since this
   applies after symlink resolution, that will return false for
   existing but broken symlinks. Use [[ -e /path/to/file || -L
   /path/to/file ]] to account for that (requires search access
   to the directory).

But that's probably going to confuse the reader more than help
them.

To confuse them even more, we could also mention
(){(($#))} (#I)/path/to/file(|)(N) to really check for file
being an entry in /path/to (requires read access to the
directory and extendedglob for (#I) used to cancel nocaseglob
in case it's enabled).

IIRC the "test" operator was initially "-a" (for "accessible"?)
for that which was a bit more accurrate (or maybe it was a
SYSV-sh vs ksh thing, I can't remember).

See also
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash/40046642#40046642

-- 
Stephane

  reply	other threads:[~2020-04-13 14:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 15:15 Vincent Lefevre
2020-04-11 17:34 ` Stephane Chazelas
2020-04-11 19:17   ` Vincent Lefevre
2020-04-11 20:37     ` Stephane Chazelas
2020-04-11 23:48       ` Vincent Lefevre
2020-04-12  1:21         ` Daniel Shahaf
2020-04-12  2:17           ` Vincent Lefevre
2020-04-12  7:09             ` Stephane Chazelas
2020-04-12 14:25               ` Vincent Lefevre
2020-04-12 17:34                 ` Stephane Chazelas
2020-04-12 23:38                   ` Vincent Lefevre
2020-04-13 14:22                     ` Stephane Chazelas [this message]
2020-04-13 15:00                       ` Bart Schaefer
2020-04-13 21:41                       ` Vincent Lefevre
2020-04-14  6:18                         ` Stephane Chazelas
2020-04-14 12:02                           ` Daniel Shahaf
2020-04-14 12:38                             ` Stephane Chazelas
2020-04-15  0:44                               ` Daniel Shahaf
2020-04-15  9:17                                 ` Vincent Lefevre
2020-04-14 17:59                           ` Vincent Lefevre
2020-04-12 12:48   ` Peter Stephenson
2020-04-12 14:31     ` Vincent Lefevre
2020-04-12 15:49       ` Peter Stephenson
2020-04-12 23:07         ` Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200413142257.orwzb4jrgmf7gpoi@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).