diff options
author | Peter Stephenson <pws@zsh.org> | 2017-01-12 13:54:29 +0000 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2017-01-12 13:54:29 +0000 |
commit | 33799ae2b00c09445e2e47720bc740ec434416e4 (patch) | |
tree | 5ad8280e25112174a72c7924d637fb9fd44db2b3 /Src/builtin.c | |
parent | d3cf8816dce8f41bba2436045f38e9884ba04cc0 (diff) | |
download | zsh-33799ae2b00c09445e2e47720bc740ec434416e4.tar.gz zsh-33799ae2b00c09445e2e47720bc740ec434416e4.tar.xz zsh-33799ae2b00c09445e2e47720bc740ec434416e4.zip |
40335: More care with autoload function path.
If doing "autoload -X", the path present might actually be location of file containing the function with the autoload -X. Add an explicit flag to say it's a directory for autoload.
Diffstat (limited to 'Src/builtin.c')
-rw-r--r-- | Src/builtin.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Src/builtin.c b/Src/builtin.c index b986dd89a..716ddd429 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2936,10 +2936,11 @@ check_autoload(Shfunc shf, char *name, Options ops, int func) { return eval_autoload(shf, name, ops, func); } - if (OPT_ISSET(ops,'r') || OPT_ISSET(ops,'R')) + if ((OPT_ISSET(ops,'r') || OPT_ISSET(ops,'R')) && + (shf->node.flags & PM_UNDEFINED)) { char *dir_path; - if (shf->filename) { + if (shf->filename && (shf->node.flags & PM_LOADDIR)) { char *spec_path[2]; spec_path[0] = shf->filename; spec_path[1] = NULL; @@ -2964,6 +2965,7 @@ check_autoload(Shfunc shf, char *name, Options ops, int func) dir_path = xsymlink(dir_path, 1); } shf->filename = ztrdup(dir_path); + shf->node.flags |= PM_LOADDIR; return 0; } if (OPT_ISSET(ops,'R')) { @@ -3017,7 +3019,8 @@ add_autoload_function(Shfunc shf, char *funcname) { char *nam; if (*funcname == '/' && funcname[1] && - (nam = strrchr(funcname, '/')) && nam[1]) { + (nam = strrchr(funcname, '/')) && nam[1] && + (shf->node.flags & PM_UNDEFINED)) { char *dir; nam = strrchr(funcname, '/'); if (nam == funcname) { @@ -3028,6 +3031,7 @@ add_autoload_function(Shfunc shf, char *funcname) } zsfree(shf->filename); shf->filename = ztrdup(dir); + shf->node.flags |= PM_LOADDIR; shfunctab->addnode(shfunctab, ztrdup(nam), shf); } else { shfunctab->addnode(shfunctab, ztrdup(funcname), shf); @@ -3278,6 +3282,7 @@ bin_functions(char *name, char **argv, Options ops, int func) if (*argv) { zsfree(shf->filename); shf->filename = ztrdup(*argv); + on |= PM_LOADDIR; } shf->node.flags = on; ret = eval_autoload(shf, funcname, ops, func); |