From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 18017 invoked from network); 12 Apr 2020 14:26:33 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with UTF8ESMTPZ; 12 Apr 2020 14:26:33 -0000 Received: (qmail 21928 invoked by alias); 12 Apr 2020 14:26:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45682 Received: (qmail 15443 invoked by uid 1010); 12 Apr 2020 14:26:24 -0000 X-Qmail-Scanner-Diagnostics: from joooj.vinc17.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25772. spamassassin: 3.4.4. Clear:RC:0(155.133.131.76):SA:0(-1.9/5.0):. Processed in 1.691358 secs); 12 Apr 2020 14:26:24 -0000 X-Envelope-From: vincent@vinc17.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at vinc17.net does not designate permitted sender hosts) Date: Sun, 12 Apr 2020 16:25:44 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: glob qualifier '-' doesn't work correctly on dangling symlinks Message-ID: <20200412142544.GA1783815@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20200411151511.GA1708902@zira.vinc17.org> <20200411173450.56nnznxtmil5oge3@chazelas.org> <20200411191711.GA1722320@zira.vinc17.org> <20200411203714.wupg6wmd7b7xch2w@chazelas.org> <20200411234817.GA1737986@zira.vinc17.org> <20200412012155.7954a35f@tarpaulin.shahaf.local2> <20200412021722.GA1748686@zira.vinc17.org> <20200412070930.etfzj6j2qvd5em7b@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200412070930.etfzj6j2qvd5em7b@chazelas.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.12.1+33 (6a74e24e) vl-117499 (2019-06-23) On 2020-04-12 08:09:30 +0100, Stephane Chazelas wrote: > 2020-04-12 04:17:22 +0200, Vincent Lefevre: > > zira% ln -s /does-not-exist s1 > > zira% ln -s /root/foo s2 > > zira% ls -L s* > > ls: cannot access 's1': No such file or directory > > ls: cannot access 's2': Permission denied > > > > But with glob qualifiers, there does not seem to be a way to > > distinguish these two cases. > [...] > > There's: > > $ zmodload zsh/system > $ ls -ld -- *(e[ERRNO=0]-e['[[ $errnos[ERRNO] = EACCES ]]']) > lrwxrwxrwx 1 chazelas chazelas 9 Apr 12 07:34 s2 -> /root/foo > $ ls -ld -- *(e[ERRNO=0]-e['[[ $errnos[ERRNO] = ENOENT ]]']) > lrwxrwxrwx 1 chazelas chazelas 15 Apr 12 07:34 s1 -> /does-not-exist > > (the ERRNO=0 may not be necessary). Well, I implicitly meant with simple glob qualifiers. Otherwise, when allowing 'e' (to run arbitrary code), one can do almost anything based on available information. > Note: > > $ find -L . -perm -o=w > ./s1 > find: ‘./s2’: Permission denied > > But again, *(-@) for broken symlinks is documented and widely > used, we can't break that. But widely used for what purpose exactly? For instance, if the goal is to list dangling symlinks only, then "permission denied" cases (EACCES) would yield false positives, and existing code may be broken. So, perhaps '-' should still be kept for dangling symlinks, but its behavior might need to be changed to match the currently expected behavior. And what about less common errors such as ENOMEM? > So if we change "-" to exclude broken symlinks, we'd need to > special case -@. What's the scope of what should be special > cased? *(-@e['((count++))']) should probably still work as well > for instance. > > How about: *(-e['((n++))']@['((brokenlinks++))'])? > > And *(-@m-1) (broken links created in the last 24 hours, though > I'd expect one to write *(m-1-@) instead here) > > Note that for "find -L", zsh's current behaviour is required by > POSIX (at least for links whose target can be determined not to > exist): > > -L > Cause the file information and file type evaluated for > each symbolic link encountered as a path operand on > the command line or encountered during the traversal > of a file hierarchy to be those of the file referenced > by the link, and not the link itself. If the > ^^^^^^ > referenced file does not exist, the file information > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > and type shall be for the link itself. > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ At least, that's explicit, unambiguous documentation. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)