Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion doesn't work on symlink to . with ignore-parents



On Mon, 26 Jul 2010 14:41:18 +0200
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> On 2010-06-29 10:54:49 +0200, Vincent Lefevre wrote:
> > ypig% ln -s . symlink
> > ypig% ls -l symlink
> > lrwxrwxrwx 1 vlefevre vlefevre 1 2010-06-29 10:48:49 symlink -> .
> > ypig% zstyle ':completion:*' completer _complete
> > ypig% zstyle ':completion:*' ignore-parents parent pwd
> > ypig% autoload -U compinit
> > ypig% compinit
> > ypig% rm sym[TAB]
> > 
> > doesn't complete to anything.
> > 
> > I have zsh 4.3.10 with some patches.
> 
> Any news? This problem still occurs with zsh 4.3.10-dev-2.

It might be this simple.  The function in question appears only to do
comparison on device and inode.  If, as this bug report suggests, it's
wrong to ignore symbolic links to the file in question, then always doing
an lstat() is presumably correct.  However, the function is about three
levels of undocumentation deep inside the completion system.  I've added a
lonely comment saying what I think is going on.

Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.118
diff -p -u -r1.118 computil.c
--- Src/Zle/computil.c	22 Jan 2010 20:42:32 -0000	1.118
+++ Src/Zle/computil.c	26 Jul 2010 13:05:38 -0000
@@ -4653,6 +4653,15 @@ cf_pats(int dirs, int noopt, LinkList na
 			 names, skipped, sdirs, fake);
 }
 
+/*
+ * This function looks at device/inode pairs to determine if
+ * a file is one we should ignore because of its relationship
+ * to the current or parent directory.
+ *
+ * We don't follow symbolic links here, because typically
+ * a user will not want an explicit link to the current or parent
+ * directory ignored.
+ */
 static void
 cf_ignore(char **names, LinkList ign, char *style, char *path)
 {
@@ -4661,14 +4670,14 @@ cf_ignore(char **names, LinkList ign, ch
     char *n, *c, *e;
 
     tpar = !!strstr(style, "parent");
-    if ((tpwd = !!strstr(style, "pwd")) && stat(pwd, &est))
+    if ((tpwd = !!strstr(style, "pwd")) && lstat(pwd, &est))
 	tpwd = 0;
 
     if (!tpar && !tpwd)
 	return;
 
     for (; (n = *names); names++) {
-	if (!ztat(n, &nst, 0) && S_ISDIR(nst.st_mode)) {
+	if (!ztat(n, &nst, 1) && S_ISDIR(nst.st_mode)) {
 	    if (tpwd && nst.st_dev == est.st_dev && nst.st_ino == est.st_ino) {
 		addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH));
 		continue;
@@ -4684,7 +4693,7 @@ cf_ignore(char **names, LinkList ign, ch
 		    }
 		}
 		if (found || ((e = strrchr(c, '/')) && e > c + pl &&
-			      !ztat(c, &st, 0) && st.st_dev == nst.st_dev &&
+			      !ztat(c, &st, 1) && st.st_dev == nst.st_dev &&
 			      st.st_ino == nst.st_ino))
 		    addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH));
 	    }
-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author