From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26076 invoked from network); 26 Mar 2008 16:22:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Mar 2008 16:22:45 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 21846 invoked from network); 26 Mar 2008 16:22:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Mar 2008 16:22:41 -0000 Received: (qmail 4691 invoked by alias); 26 Mar 2008 16:22:39 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24750 Received: (qmail 4676 invoked from network); 26 Mar 2008 16:22:38 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 26 Mar 2008 16:22:38 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id EAB708097D31 for ; Wed, 26 Mar 2008 17:22:31 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly11g.srv.mailcontrol.com (MailControl) with ESMTP id m2QGLOdr024489 for ; Wed, 26 Mar 2008 16:22:28 GMT Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Wed, 26 Mar 2008 16:21:51 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.14.2/8.13.4) with ESMTP id m2QGLqvb017969 for ; Wed, 26 Mar 2008 16:21:52 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.14.2/8.14.2/Submit) with ESMTP id m2QGLptV017966 for ; Wed, 26 Mar 2008 16:21:52 GMT Message-Id: <200803261621.m2QGLptV017966@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: _canonical_path not working on *BSD In-reply-to: <200803261604.m2QG41Ke017772@news01.csr.com> References: <20080326114413.80713vrmznwpnyuc@bapt.selfip.org> <080326083638.ZM16858@torch.brasslantern.com> <200803261540.m2QFeJmm017381@news01.csr.com> <200803261604.m2QG41Ke017772@news01.csr.com> Comments: In-reply-to Peter Stephenson message dated "Wed, 26 Mar 2008 16:04:01 +0000." Date: Wed, 26 Mar 2008 16:21:51 +0000 From: Peter Stephenson X-OriginalArrivalTime: 26 Mar 2008 16:21:51.0836 (UTC) FILETIME=[7FC449C0:01C88F5D] X-Scanned-By: MailControl A-08-00-04 (www.mailcontrol.com) on 10.71.0.121 X-Virus-Scanned: ClamAV 0.91.2/6396/Wed Mar 26 12:29:12 2008 on bifrost X-Virus-Status: Clean Peter Stephenson wrote: > Hmm... sorry about all the traffic... actually, it still doesn't > guarantee to give a canonical path as "readlink -f" does, since it > doesn't check if the value returned is itself a symbolic link, and also > it returns empty instead of the original file if it wasn't a link. We would > need to do something like the following... if I've correctly divined > that the intention in both cases is that if a file exists at all we > should always use the name, but converted to the canonical form. Sigh. Or even this. This time, I've guarded against loops in the symbolic links. I'm still not quite sure what the test of the status from readlink in the second case was for, seeing as "readlink -qf /nonexistent" returns status 0. I've interpreted it as a test for a file that actually exists. In the present context it may not matter. Index: Completion/Unix/Type/_canonical_paths =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_canonical_paths,v retrieving revision 1.1 diff -u -r1.1 _canonical_paths --- Completion/Unix/Type/_canonical_paths 28 May 2006 18:36:06 -0000 1.1 +++ Completion/Unix/Type/_canonical_paths 26 Mar 2008 16:16:14 -0000 @@ -27,18 +27,38 @@ shift 2 -if (( ! $+commands[readlink] )); then +if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=0 return ret fi +typeset REPLY typeset -a matches files +_canonical_paths_get_canonical_path() { + typeset newfile + typeset -A seen + + REPLY=$1 + # Guard against loops. + while [[ -z ${seen[$REPLY]} ]]; do + seen[$REPLY]=1 + newfile=$(zstat +link $REPLY 2>/dev/null) + if [[ -n $newfile ]]; then + REPLY=$newfile + else + break + fi + done +} + + if (( $__opts[(I)-N] )); then files=($@) else for __index in $@; do - files+=$(readlink -qf $__index) + _canonical_paths_get_canonical_path $__index + files+=($REPLY) done fi @@ -48,8 +68,9 @@ expref=${~origpref} [[ $origpref == (|*/). ]] && rltrim=. curpref=${${expref%$rltrim}:-./} - canpref=$(readlink -qf $curpref) - if [[ $? -eq 0 ]]; then + if zstat $curpref >&/dev/null; then + _canonical_paths_get_canonical_path $curpref + canpref=$REPLY [[ $curpref == */ && $canpref == *[^/] ]] && canpref+=/ canpref+=$rltrim [[ $expref == *[^/] && $canpref == */ ]] && origpref+=/ -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070