mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-09-27 22:40:20 +02:00
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.
This commit is contained in:
parent
d3cf8816dc
commit
33799ae2b0
@ -1,5 +1,9 @@
|
||||
2017-01-12 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 40335: Src/builtin.c, Src/exec.c, Src/zsh.h,
|
||||
Test/C04funcdef.ztst: be more careful autoload filename is
|
||||
directory, not source location.
|
||||
|
||||
* Jens Elkner: 40333: Src/watch.c: Fix the utmpx interface for
|
||||
watch as otherwise it failed on some OSes.
|
||||
|
||||
|
@ -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);
|
||||
|
@ -5160,7 +5160,8 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
|
||||
pushheap();
|
||||
|
||||
noaliases = (shf->node.flags & PM_UNALIASED);
|
||||
if (shf->filename && shf->filename[0] == '/')
|
||||
if (shf->filename && shf->filename[0] == '/' &&
|
||||
(shf->node.flags & PM_LOADDIR))
|
||||
{
|
||||
char *spec_path[2];
|
||||
spec_path[0] = dupstring(shf->filename);
|
||||
@ -5203,7 +5204,7 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
|
||||
shf->funcdef = prog;
|
||||
else
|
||||
shf->funcdef = dupeprog(prog, 0);
|
||||
shf->node.flags &= ~PM_UNDEFINED;
|
||||
shf->node.flags &= ~(PM_UNDEFINED|PM_LOADDIR);
|
||||
zsfree(shf->filename);
|
||||
shf->filename = fname;
|
||||
} else {
|
||||
@ -5227,7 +5228,7 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
|
||||
shf->funcdef = stripkshdef(prog, shf->node.nam);
|
||||
else
|
||||
shf->funcdef = dupeprog(stripkshdef(prog, shf->node.nam), 0);
|
||||
shf->node.flags &= ~PM_UNDEFINED;
|
||||
shf->node.flags &= ~(PM_UNDEFINED|PM_LOADDIR);
|
||||
zsfree(shf->filename);
|
||||
shf->filename = fname;
|
||||
}
|
||||
|
@ -1823,6 +1823,7 @@ struct tieddata {
|
||||
|
||||
/* Remaining flags do not correspond directly to command line arguments */
|
||||
#define PM_DONTIMPORT_SUID (1<<19) /* do not import if running setuid */
|
||||
#define PM_LOADDIR (1<<19) /* (function) filename gives load directory */
|
||||
#define PM_SINGLE (1<<20) /* special can only have a single instance */
|
||||
#define PM_LOCAL (1<<21) /* this parameter will be made local */
|
||||
#define PM_SPECIAL (1<<22) /* special builtin parameter */
|
||||
|
@ -419,6 +419,16 @@
|
||||
0:autoload -dX with path
|
||||
>I have been loaded by default path.
|
||||
|
||||
(
|
||||
fpath=(.)
|
||||
print 'loadthisfunc() { autoload -X }' >loadthisfunc_sourceme
|
||||
print 'print Function was loaded correctly.' >loadthisfunc
|
||||
source $PWD/loadthisfunc_sourceme
|
||||
loadthisfunc
|
||||
)
|
||||
0: autoload -X interaction with absolute filename used for source location
|
||||
>Function was loaded correctly.
|
||||
|
||||
%clean
|
||||
|
||||
rm -f file.in file.out
|
||||
|
Loading…
Reference in New Issue
Block a user