From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17872 invoked from network); 1 Nov 2001 16:30:51 -0000 Received: from ns2.primenet.com.au (HELO primenet.com.au) (?DECoEO37B0wLv7zYh0Yoxz1bl6eU+zSB?@203.24.36.3) by ns1.primenet.com.au with SMTP; 1 Nov 2001 16:30:51 -0000 Received: (qmail 11180 invoked from network); 1 Nov 2001 16:30:50 -0000 Received: from sunsite.dk (130.225.247.90) by proxy.melb.primenet.com.au with SMTP; 1 Nov 2001 16:30:50 -0000 Received: (qmail 19955 invoked by alias); 1 Nov 2001 16:30:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16201 Received: (qmail 19942 invoked from network); 1 Nov 2001 16:30:41 -0000 From: Bart Schaefer Message-Id: <1011101163034.ZM647@candle.brasslantern.com> Date: Thu, 1 Nov 2001 16:30:34 +0000 In-Reply-To: <16306.1004629235@csr.com> Comments: In reply to Peter Stephenson "Re: named directory bug" (Nov 1, 3:40pm) References: <16306.1004629235@csr.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Peter Stephenson , zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: named directory bug MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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