From: Pea <zsh@raveland.org>
To: Peter Stephenson <pws@csr.com>
Cc: Baptiste Daroussin <baptiste.daroussin@gmail.com>,
zsh-workers@sunsite.dk
Subject: Re: _canonical_path not working on *BSD
Date: Wed, 26 Mar 2008 17:25:33 +0100 [thread overview]
Message-ID: <20080326172533.0b587b55@coredump.raveland.priv> (raw)
In-Reply-To: <200803261604.m2QG41Ke017772@news01.csr.com>
Le Wed, 26 Mar 2008 16:04:01 +0000,
Peter Stephenson <pws@csr.com> a écrit :
> Peter Stephenson wrote:
> > Bart Schaefer wrote:
> > > On Mar 26, 11:44am, Baptiste Daroussin wrote:
> > > }
> > > } _canonical_path is not working on freebsd, it rely on readlink
> > >
> > > Try this. I don't actually have any mount points that are symlink
> > > targets so it's hard to test, but I think this is right:
> > >
> > > -if (( ! $+commands[readlink] )); then
> > > +if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
> >
> > That's probably a better solution; it doesn't necessarily work on
> > all systems, particularly if the shell is statically linked, but it
> > should be at least as widely applicable as, and easier to test for
> > than, anything involving readlink.
>
> 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.
>
> 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 15:58:52 -0000 @@ -27,18 +27,28 @@
>
> 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 addfile newfile
> typeset -a matches files
>
> if (( $__opts[(I)-N] )); then
> files=($@)
> else
> for __index in $@; do
> - files+=$(readlink -qf $__index)
> + addfile=$__index
> + while true; do
> + newfile=$(zstat +link $addfile)
> + if [[ -n $newfile ]]; then
> + addfile=$newfile
> + else
> + break
> + fi
> + done
> + files+=($addfile)
> done
> fi
>
> @@ -48,8 +58,18 @@
> expref=${~origpref}
> [[ $origpref == (|*/). ]] && rltrim=.
> curpref=${${expref%$rltrim}:-./}
> - canpref=$(readlink -qf $curpref)
> - if [[ $? -eq 0 ]]; then
> + if zstat $curpref >&/dev/null; then
> + canpref=$curpref
> + while true; do
> + newfile=$(zstat +link $canpref)
> + if [[ -n $newfile ]]; then
> + canpref=$newfile
> + else
> + break
> + fi
> + done
> + fi
> + if [[ -n "$canpref" ]]; then
> [[ $curpref == */ && $canpref == *[^/] ]] && canpref+=/
> canpref+=$rltrim
> [[ $expref == *[^/] && $canpref == */ ]] && origpref+=/
>
>
This patch doesn't work on OpenBSD (-current @i386).
umount [TAB] gives me:
[pea@coredump:~]% umount _canonical_paths_add_paths:zstat:1:
usr/src/sys: no such file or directory
_canonical_paths_add_paths:zstat:1: usr/src/sys: no such file or
directory
umount
/ /dev/sd0a /dev/svnd0a /home/pea
prev parent reply other threads:[~2008-03-26 16:25 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-26 10:44 Baptiste Daroussin
2008-03-26 15:01 ` Debian bugs (Re: _canonical_path not working on *BSD) Bart Schaefer
2008-03-26 15:25 ` Clint Adams
2008-03-26 15:05 ` _canonical_path not working on *BSD Peter Stephenson
2008-03-26 15:27 ` Baptiste Daroussin
2008-03-26 15:34 ` Peter Stephenson
2008-03-26 15:51 ` Pea
2008-03-26 15:59 ` Clint Adams
2008-03-26 15:21 ` Pea
2008-03-26 15:36 ` Bart Schaefer
2008-03-26 15:40 ` Peter Stephenson
2008-03-26 16:04 ` Peter Stephenson
2008-03-26 16:18 ` Bart Schaefer
2008-03-26 16:21 ` Peter Stephenson
2008-03-26 16:38 ` Pea
2008-03-26 16:46 ` Peter Stephenson
2008-03-26 17:08 ` Pea
2008-03-26 17:17 ` Baptiste Daroussin
2008-03-27 10:23 ` Peter Stephenson
2008-03-27 11:08 ` Pea
2008-03-27 11:25 ` Peter Stephenson
2008-03-27 12:15 ` PATCH: cd -q (was Re: _canonical_path ...) Peter Stephenson
2008-03-27 12:25 ` Stephane Chazelas
2008-03-27 12:35 ` Mikael Magnusson
2008-03-27 12:48 ` Peter Stephenson
2008-03-27 12:56 ` Mikael Magnusson
2008-03-27 18:45 ` Peter Stephenson
2008-03-28 8:16 ` Pea
2008-03-28 11:01 ` Mikael Magnusson
2008-03-28 14:35 ` Peter Stephenson
2008-03-27 12:31 ` _canonical_path not working on *BSD Pea
2008-03-27 15:39 ` Bart Schaefer
2008-03-27 18:06 ` Peter Stephenson
2008-03-28 1:01 ` Bart Schaefer
2008-03-28 7:51 ` Mikael Magnusson
2008-03-28 10:01 ` Peter Stephenson
2008-03-26 16:25 ` Pea [this message]
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=20080326172533.0b587b55@coredump.raveland.priv \
--to=zsh@raveland.org \
--cc=baptiste.daroussin@gmail.com \
--cc=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/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).