Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cd bugs
- X-seq: zsh-workers 27167
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: cd bugs
- Date: Sun, 19 Jul 2009 20:00:41 +0100
- In-reply-to: <loom.20090714T222350-609@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <loom.20090714T205419-391@xxxxxxxxxxxxxx> <loom.20090714T222350-609@xxxxxxxxxxxxxx>
On Tue, 14 Jul 2009 22:30:33 +0000 (UTC)
Eric Blake <ebb9@xxxxxxx> wrote:
> Another bug - POSIX requires that CDPATH be searched prior to ., regardless of
> whether CDPATH contains an explicit . or an empty entry.
Here's the option for this---obviously the other POSIX behaviour can be
associated with it, I just haven't done that here.
I also haven't bothered with optimising the case where we already tested
"." within CDPATH, it's not worth the extra code.
Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.123
diff -u -r1.123 builtins.yo
--- Doc/Zsh/builtins.yo 2 Jul 2009 13:48:29 -0000 1.123
+++ Doc/Zsh/builtins.yo 19 Jul 2009 18:56:20 -0000
@@ -183,6 +183,9 @@
successful. If `tt(.)' occurs in tt(cdpath), then tt(cdpath) is searched
strictly in order so that `tt(.)' is only tried at the appropriate point.
+The order of testing tt(cdpath) is modified if the option tt(POSIX_CD)
+is set, as described in the documentation for the option.
+
If no directory is found, the option tt(CDABLE_VARS) is set, and a
parameter named var(arg) exists whose value begins with a slash, treat its
value as the directory. In that case, the parameter is added to the named
Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.84
diff -u -r1.84 options.yo
--- Doc/Zsh/options.yo 12 Jul 2009 15:10:07 -0000 1.84
+++ Doc/Zsh/options.yo 19 Jul 2009 18:56:21 -0000
@@ -115,6 +115,22 @@
will be treated as referring to the physical parent, even if the preceding
path segment is a symbolic link.
)
+pindex(POSIX_CD)
+pindex(POSIXCD)
+pindex(NO_POSIX_CD)
+pindex(NOPOSIXCD)
+cindex(CDPATH, order of checking)
+item(tt(POSIX_CD))(
+Modifies the behaviour of tt(cd), tt(chdir) and tt(pushd) commands
+to make them more compatible with the POSIX standard. The behaviour with
+the option unset is described in the documentation for the tt(cd)
+builtin in
+ifzman(zmanref(zshbuiltins))\
+ifnzman(noderef(Shell Builtin Commands)).
+If the option is set, the shell does not test for directories beneath
+the local directory (`tt(.)') until after all directories in tt(cdpath)
+have been tested.
+)
pindex(PUSHD_IGNORE_DUPS)
pindex(NO_PUSHD_IGNORE_DUPS)
pindex(PUSHDIGNOREDUPS)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.231
diff -u -r1.231 builtin.c
--- Src/builtin.c 15 Jul 2009 08:43:31 -0000 1.231
+++ Src/builtin.c 19 Jul 2009 18:56:21 -0000
@@ -945,14 +945,23 @@
return NULL;
}
- /* if cdpath is being used, check it for . */
- if (!nocdpath)
+ /*
+ * If cdpath is being used, check it for ".".
+ * Don't bother doing this if POSIXCD is set, we don't
+ * need to know (though it doesn't actually matter).
+ */
+ if (!nocdpath && !isset(POSIXCD))
for (pp = cdpath; *pp; pp++)
if (!(*pp)[0] || ((*pp)[0] == '.' && (*pp)[1] == '\0'))
hasdot = 1;
- /* if there is no . in cdpath (or it is not being used), try the directory
- as-is (i.e. from .) */
- if (!hasdot) {
+ /*
+ * If
+ * (- there is no . in cdpath
+ * - or cdpath is not being used)
+ * - and the POSIXCD option is not set
+ * try the directory as-is (i.e. from .)
+ */
+ if (!hasdot && !isset(POSIXCD)) {
if ((ret = cd_try_chdir(NULL, dest, hard)))
return ret;
if (errno != ENOENT)
@@ -971,6 +980,15 @@
if (errno != ENOENT)
eno = errno;
}
+ /*
+ * POSIX requires us to check "." after CDPATH rather than before.
+ */
+ if (isset(POSIXCD)) {
+ if ((ret = cd_try_chdir(NULL, dest, hard)))
+ return ret;
+ if (errno != ENOENT)
+ eno = errno;
+ }
/* handle the CDABLEVARS option */
if ((ret = cd_able_vars(dest))) {
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.50
diff -u -r1.50 options.c
--- Src/options.c 10 Jul 2009 11:08:48 -0000 1.50
+++ Src/options.c 19 Jul 2009 18:56:22 -0000
@@ -200,6 +200,7 @@
{{NULL, "pathdirs", OPT_EMULATE}, PATHDIRS},
{{NULL, "posixaliases", OPT_EMULATE|OPT_BOURNE}, POSIXALIASES},
{{NULL, "posixbuiltins", OPT_EMULATE|OPT_BOURNE}, POSIXBUILTINS},
+{{NULL, "posixcd", OPT_EMULATE|OPT_BOURNE}, POSIXCD},
{{NULL, "posixidentifiers", OPT_EMULATE|OPT_BOURNE}, POSIXIDENTIFIERS},
{{NULL, "posixjobs", OPT_EMULATE|OPT_BOURNE}, POSIXJOBS},
{{NULL, "printeightbit", 0}, PRINTEIGHTBIT},
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.160
diff -u -r1.160 zsh.h
--- Src/zsh.h 11 Jul 2009 16:43:00 -0000 1.160
+++ Src/zsh.h 19 Jul 2009 18:56:22 -0000
@@ -1966,6 +1966,7 @@
PATHDIRS,
POSIXALIASES,
POSIXBUILTINS,
+ POSIXCD,
POSIXIDENTIFIERS,
POSIXJOBS,
PRINTEIGHTBIT,
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author