Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _canonical_path not working on *BSD
- X-seq: zsh-workers 24758
- From: Pea <zsh@xxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: _canonical_path not working on *BSD
- Date: Thu, 27 Mar 2008 12:08:07 +0100
- Cc: zsh-workers@xxxxxxxxxx
- In-reply-to: <20080327102325.55808716@news01>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: Raveland
- References: <20080326114413.80713vrmznwpnyuc@xxxxxxxxxxxxxxx> <080326083638.ZM16858@xxxxxxxxxxxxxxxxxxxxxx> <200803261540.m2QFeJmm017381@xxxxxxxxxxxxxx> <200803261604.m2QG41Ke017772@xxxxxxxxxxxxxx> <200803261621.m2QGLptV017966@xxxxxxxxxxxxxx> <20080326173824.0a55c00d@xxxxxxxxxxxxxxxxxxxxxx> <20080326164615.1d5893ed@news01> <20080327102325.55808716@news01>
Le Thu, 27 Mar 2008 10:23:25 +0000,
Peter Stephenson <pws@xxxxxxx> a écrit :
> On Wed, 26 Mar 2008 16:46:15 +0000
> Peter Stephenson <pws@xxxxxxx> wrote:
> > +_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
> > +}
>
> 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.
>
> Luckily, we have the technology, I think.
>
> 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.
>
> Index: Completion/Unix/Type/_canonical_paths
> ===================================================================
> 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
>
> _canonical_paths_get_canonical_path() {
> - typeset newfile
> + typeset newfile dir
> typeset -A seen
>
> REPLY=$1
> - # Guard against loops.
> + # Resolve any trailing symbolic links, guarding against loops.
> while [[ -z ${seen[$REPLY]} ]]; do
> seen[$REPLY]=1
> - newfile=$(zstat +link $REPLY 2>/dev/null)
> - if [[ -n $newfile ]]; then
> - REPLY=$newfile
> + newfile=()
> + zstat -A newfile +link $REPLY 2>/dev/null
> + if [[ -n $newfile[1] ]]; then
> + REPLY=$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="$(unfunction chpwd
> + setopt CHASE_LINKS
> + cd $REPLY 2>/dev/null && pwd)"
> + if [[ -n $dir ]]; then
> + REPLY=$dir
> + fi
> + elif [[ $REPLY = */*[^/] && $REPLY != /[^/]# ]]; then
> + # Don't try this if there's a trailing slash or we're in
> + # the root directory.
> + dir="$(unfunction chpwd
> + setopt CHASE_LINKS
> + cd ${REPLY%/*} 2>/dev/null && pwd)"
> + if [[ -n $dir ]]; then
> + REPLY=$dir/${REPLY##*/}
> + fi
> + fi
> }
>
>
>
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 element: chpwd
_canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd
_canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd
_canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd
_canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd
umount
/ /dev/svnd0c /dev/wd0a /home/pea
--
Pierre-Emmanuel André <pea at raveland.org>
GPG key: 0x7AE329DC
Messages sorted by:
Reverse Date,
Date,
Thread,
Author