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

Re: named directory bug



On Nov 1,  3:40pm, Peter Stephenson wrote:
}
} Bart Schaefer wrote:
} > I've thought using parameters for named directories was a bad idea for a
} > very long time, ever since my csh-junkie hack of `chpwd () { cwd=$PWD }'
} > started causing `~cwd' to show up in my prompt.  (Guess when autonamedirs
} > became an option rather than the default behavior.)  At the very least I
} > think there should be a parameter flag for "this parameter is a nameddir"
} > checked by unsetparam_pm() and strsetfn() before calling adduserdir().
} 
} Would it help if we avoid local variables becoming directory names, or at
} least checked if there was already a name before adding one for a local
} variable?

That might help this bug, but it'd introduce others.

At present the only connection between the paramtab and the nameddirtab is
by the name of the parameter.  If the same name exists in both places, then
changing the parameter clobbers the nameddir.

Skipping the nameddir change for local parameters would prevent the problem
with name clashes, but it would break code that actually uses local params
as nameddirs; e.g., currently something like this works:

	foo() {
	    local t=$TMPPREFIX:h
	    echo ~t
	}

However, the patches to add a PM_NAMEDDIR flag are pretty minimal; in fact,
here they are, except that I haven't modified `typeset' to be able to set
the flag explicitly (`-d' is available) -- but maybe it never needs to be
set explicitly.

Index: Src/utils.c
===================================================================
--- Src/utils.c	2001/10/22 14:36:45	1.9
+++ Src/utils.c	2001/11/01 16:04:00
@@ -571,6 +571,7 @@
     if ((pm = (Param) paramtab->getnode(paramtab, name)) &&
 	    (PM_TYPE(pm->flags) == PM_SCALAR) &&
 	    (str = getsparam(name)) && *str == '/') {
+	pm->flags |= PM_NAMEDDIR;
 	adduserdir(name, str, 0, 1);
 	return str;
     }
Index: Src/params.c
===================================================================
--- Src/params.c	2001/07/10 09:05:21	1.11
+++ Src/params.c	2001/11/01 16:02:16
@@ -2149,6 +2149,7 @@
 	paramtab->addnode(paramtab, oldpm->nam, oldpm);
 	if ((PM_TYPE(oldpm->flags) == PM_SCALAR) &&
 	    !(pm->flags & PM_HASHELEM) &&
+	    (oldpm->flags & PM_NAMEDDIR) &&
 	    oldpm->sets.cfn == strsetfn)
 	    adduserdir(oldpm->nam, oldpm->u.str, 0, 0);
 	if (oldpm->flags & PM_EXPORTED) {
@@ -2233,8 +2234,11 @@
 {
     zsfree(pm->u.str);
     pm->u.str = x;
-    if (!(pm->flags & PM_HASHELEM))
+    if (!(pm->flags & PM_HASHELEM) &&
+	((pm->flags & PM_NAMEDDIR) || isset(AUTONAMEDIRS))) {
+	pm->flags |= PM_NAMEDDIR;
 	adduserdir(pm->nam, x, 0, 0);
+    }
 }
 
 /* Function to get value of an array parameter */

Index: Src/zsh.h
===================================================================
--- Src/zsh.h	2001/10/17 14:38:29	1.8
+++ Src/zsh.h	2001/11/01 15:46:08
@@ -1134,6 +1134,7 @@
 #define PM_AUTOLOAD	(1<<23) /* autoloaded from module                   */
 #define PM_NORESTORE	(1<<24)	/* do not restore value of local special    */
 #define PM_HASHELEM     (1<<25) /* is a hash-element */
+#define PM_NAMEDDIR     (1<<26) /* has a corresponding nameddirtab entry    */
 
 /* The option string corresponds to the first of the variables above */
 #define TYPESET_OPTSTR "aiEFALRZlurtxUhHT"

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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