From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29305 invoked from network); 27 Mar 2008 11:08:21 -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; 27 Mar 2008 11:08:21 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 56920 invoked from network); 27 Mar 2008 11:08:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Mar 2008 11:08:16 -0000 Received: (qmail 24519 invoked by alias); 27 Mar 2008 11:08:14 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24758 Received: (qmail 24509 invoked from network); 27 Mar 2008 11:08:13 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 27 Mar 2008 11:08:13 -0000 Received: from puffy.raveland.org (puffy.raveland.org [195.200.166.230]) by bifrost.dotsrc.org (Postfix) with ESMTP id 09EEC82CD267 for ; Thu, 27 Mar 2008 12:08:09 +0100 (CET) Received: from localhost.pacwan.net (pea-dsktp.pacwan.net [195.200.191.158]) by puffy.raveland.org (Postfix) with ESMTP id EEF18713464; Thu, 27 Mar 2008 12:08:08 +0100 (CET) Date: Thu, 27 Mar 2008 12:08:07 +0100 From: Pea To: Peter Stephenson Cc: zsh-workers@sunsite.dk Subject: Re: _canonical_path not working on *BSD Message-ID: <20080327120807.415095ee@raveland.org> In-Reply-To: <20080327102325.55808716@news01> References: <20080326114413.80713vrmznwpnyuc@bapt.selfip.org> <080326083638.ZM16858@torch.brasslantern.com> <200803261540.m2QFeJmm017381@news01.csr.com> <200803261604.m2QG41Ke017772@news01.csr.com> <200803261621.m2QGLptV017966@news01.csr.com> <20080326173824.0a55c00d@coredump.raveland.priv> <20080326164615.1d5893ed@news01> <20080327102325.55808716@news01> Organization: Raveland X-Mailer: Claws Mail 3.3.0 (GTK+ 2.12.7; i386-unknown-openbsd4.3) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV 0.91.2/6421/Thu Mar 27 09:54:20 2008 on bifrost X-Virus-Status: Clean Le Thu, 27 Mar 2008 10:23:25 +0000, Peter Stephenson a =E9crit : > On Wed, 26 Mar 2008 16:46:15 +0000 > Peter Stephenson wrote: > > +_canonical_paths_get_canonical_path() { > > + typeset newfile > > + typeset -A seen > > + > > + REPLY=3D$1 > > + # Guard against loops. > > + while [[ -z ${seen[$REPLY]} ]]; do > > + seen[$REPLY]=3D1 > > + newfile=3D$(zstat +link $REPLY 2>/dev/null) > > + if [[ -n $newfile ]]; then > > + REPLY=3D$newfile > > + else > > + break > > + fi > > + done > > +} >=20 > I should make one more point about this before leaving the subject: > this doesn't do everything that "readlink -f" does, in particular it > doesn't remove .. path segments, strip multiple /'s or remove > symbolic link references in intervening directories. >=20 > Luckily, we have the technology, I think. >=20 > We don't need the $(...) for the zstat. It would be quite nice to > be able to get the directory canonicalization without a fork, too. >=20 > Index: Completion/Unix/Type/_canonical_paths > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_canonical_paths,v > retrieving revision 1.2 > diff -u -r1.2 _canonical_paths > --- Completion/Unix/Type/_canonical_paths 26 Mar 2008 17:22:25 > -0000 1.2 +++ Completion/Unix/Type/_canonical_paths 27 > Mar 2008 10:19:10 -0000 @@ -36,20 +36,41 @@ > typeset -a matches files > =20 > _canonical_paths_get_canonical_path() { > - typeset newfile > + typeset newfile dir > typeset -A seen > =20 > REPLY=3D$1 > - # Guard against loops. > + # Resolve any trailing symbolic links, guarding against loops. > while [[ -z ${seen[$REPLY]} ]]; do > seen[$REPLY]=3D1 > - newfile=3D$(zstat +link $REPLY 2>/dev/null) > - if [[ -n $newfile ]]; then > - REPLY=3D$newfile > + newfile=3D() > + zstat -A newfile +link $REPLY 2>/dev/null > + if [[ -n $newfile[1] ]]; then > + REPLY=3D$newfile[1] > else > break > fi > done > + > + # Canonicalise the directory path. We may not be able to > + # do this if we can't read all components. > + if [[ -d $REPLY ]]; then > + dir=3D"$(unfunction chpwd > + setopt CHASE_LINKS > + cd $REPLY 2>/dev/null && pwd)" > + if [[ -n $dir ]]; then > + REPLY=3D$dir > + fi > + elif [[ $REPLY =3D */*[^/] && $REPLY !=3D /[^/]# ]]; then > + # Don't try this if there's a trailing slash or we're in > + # the root directory. > + dir=3D"$(unfunction chpwd > + setopt CHASE_LINKS > + cd ${REPLY%/*} 2>/dev/null && pwd)" > + if [[ -n $dir ]]; then > + REPLY=3D$dir/${REPLY##*/} > + fi > + fi > } > =20 > =20 >=20 Doesn't work on OpenBSD (-current). umount [TAB] gives me: [pea@pea-dsktp:~]% umount _canonical_paths_get_canonical_path:unfunction:1:= no such hash table element: chpwd _canonical_paths_get_canonical_path:unfunction:1: no such hash table elemen= t: chpwd _canonical_paths_get_canonical_path:unfunction:1: no such hash table elemen= t: chpwd _canonical_paths_get_canonical_path:unfunction:1: no such hash table elemen= t: chpwd _canonical_paths_get_canonical_path:unfunction:1: no such hash table elemen= t: chpwd _canonical_paths_get_canonical_path:unfunction:1: no such hash table elemen= t: chpwd umount = =20 / /dev/svnd0c /dev/wd0a /home/pea --=20 Pierre-Emmanuel Andr=E9 GPG key: 0x7AE329DC