summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-02-13 16:32:50 +0000
committerPeter Stephenson <pws@zsh.org>2017-02-13 16:32:50 +0000
commitf5272bccd873e7df4cd63f13ee0e880cf832507e (patch)
treed859f55ad92c804280479e242fd512f4a1902e3b
parent64c67581d2f4d131a3c1bebdeda6b70ec7da2610 (diff)
downloadzsh-f5272bccd873e7df4cd63f13ee0e880cf832507e.tar.gz
zsh-f5272bccd873e7df4cd63f13ee0e880cf832507e.zip
40536: Prepend directory to $fpath.
Used if parent function is autoloaded by absolute path so as to find functions in the same suite without shell code modification.
-rw-r--r--ChangeLog6
-rw-r--r--Src/builtin.c36
-rw-r--r--Src/zsh.h1
3 files changed, 43 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a1cd197c..194cb3128 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-13 Peter Stephenson <p.stephenson@samsung.com>
+
+ * Sebastian: 40536: Src/builtin.c, Src/zsh.h: prepend directory
+ of function autoload with absolute path to fpath if loading a
+ function by relative path.
+
2017-02-10 Oliver Kiddle <opk@zsh.org>
* 40512: Completion/Unix/Command/_entr: new entr completion
diff --git a/Src/builtin.c b/Src/builtin.c
index 394d2069e..16784d74a 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3032,8 +3032,44 @@ add_autoload_function(Shfunc shf, char *funcname)
dircache_set(&shf->filename, NULL);
dircache_set(&shf->filename, dir);
shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
shfunctab->addnode(shfunctab, ztrdup(nam), shf);
} else {
+ Shfunc shf2;
+ Funcstack fs;
+ const char *calling_f = NULL;
+ char buf[PATH_MAX+1];
+
+ /* Find calling function */
+ for (fs = funcstack; fs; fs = fs->prev) {
+ if (fs->tp == FS_FUNC && fs->name && (!shf->node.nam || 0 != strcmp(fs->name,shf->node.nam))) {
+ calling_f = fs->name;
+ break;
+ }
+ }
+
+ /* Get its directory */
+ if (calling_f) {
+ /* Should contain load directory, and be loaded via absolute path */
+ if ((shf2 = (Shfunc) shfunctab->getnode2(shfunctab, calling_f))
+ && (shf2->node.flags & PM_LOADDIR) && (shf2->node.flags & PM_ABSPATH_USED)
+ && shf2->filename)
+ {
+ if (strlen(shf2->filename) + strlen(funcname) + 1 < PATH_MAX)
+ {
+ sprintf(buf, "%s/%s", shf2->filename, funcname);
+ /* Set containing directory if the function file
+ * exists (do normal FPATH processing otherwise) */
+ if (!access(buf, R_OK)) {
+ dircache_set(&shf->filename, NULL);
+ dircache_set(&shf->filename, shf2->filename);
+ shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
+ }
+ }
+ }
+ }
+
shfunctab->addnode(shfunctab, ztrdup(funcname), shf);
}
}
diff --git a/Src/zsh.h b/Src/zsh.h
index c3874144e..f2c279002 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1807,6 +1807,7 @@ struct tieddata {
#define PM_READONLY (1<<10) /* readonly */
#define PM_TAGGED (1<<11) /* tagged */
#define PM_EXPORTED (1<<12) /* exported */
+#define PM_ABSPATH_USED (1<<12) /* (function): loaded using absolute path */
/* The following are the same since they *
* both represent -U option to typeset */