Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Autoload and absolute paths.. Maybe after all
- X-seq: zsh-workers 40536
- From: Sebastian Gniazdowski <psprint2@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] Autoload and absolute paths.. Maybe after all
- Date: Mon, 13 Feb 2017 03:56:28 -0800
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= mesmtp; bh=9leBynv24R5vJ1HGy57dWN8IFQs=; b=gXFYy/fdn6Oi5dqCb3ZV9 0A7BibuT+/y/74b8M0iafhdffFjkMFTTNqULfl7AExb0PK76P4EOhHiFueJb9Q4j lvPfILxOtNGnGUKQwi1l9BAq90qkTi6foUA3Vq3rf1UukyMjLj/7sJgetbfQs6lj VQd9AODIJFp+IwRtVJTk1E=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=smtpout; bh=9leBynv24R5vJ1HGy57dWN8IF Qs=; b=fxJN9pg1r8s4UJnrTv9EGxZjPhMfnTHsM0wrSAWlo3afRrZLYC6EJlzEe OsJ7KoXOjM2uOo6hXlav3XEiyAZFwyKzZEJvssS4V+4nUcem1B1VlvC+Y4uvMKUP PWE83geiFC+eWzVU+ub8pO2B0wGgvJvFChvqZaQpEM7GqHNqEc=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello,
following doesn't work:
# mkdir ~/myfunctions
# mv /usr/local/share/zsh/5.3.1-dev-0/functions/calendar* ~/myfunctions
# autoload ~/myfunctions/calendar
# calendar
calendar:36: calendar_scandate: function definition file not found
called this a very big problem. Directory ~/myfunctions doesn't make
sense. Below is a patch that addresses this. Maybe the code looks good?
diff --git a/Src/builtin.c b/Src/builtin.c
index 394d206..16784d7 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 c387414..f2c2790 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 */
--
Sebastian Gniazdowski
psprint2@xxxxxxxxxxxx
diff --git a/Src/builtin.c b/Src/builtin.c
index 394d206..16784d7 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 c387414..f2c2790 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 */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author