summaryrefslogtreecommitdiffstats
path: root/src/scriptfile.c
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2024-04-16 22:11:56 +0200
committerChristian Brabandt <cb@256bit.org>2024-04-16 22:11:56 +0200
commit9a90179a11b433fcbcf587182032222e229c6d75 (patch)
tree19109477719add748d5f2b2dccdc3bca3e69dd3b /src/scriptfile.c
parentd1068a2bb09fd3b9d117d832105bf10dd5e48e2f (diff)
patch 9.1.0338: Vim9: import through symlinks not correctly handledv9.1.0338
Problem: Vim9: import through symlinks not correctly handled Solution: Check for script being a symlink but only once (Ernie Rael) closes: #14565 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/scriptfile.c')
-rw-r--r--src/scriptfile.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c
index 109e13e5c6..cc76260410 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -405,6 +405,43 @@ get_new_scriptitem_for_fname(int *error, char_u *fname)
return sid;
}
+/*
+ * If the script for "sid" is a symlink and "sn_source_sid" is not set
+ * then initialize it. A new script_item is created if needed.
+ */
+ void
+check_script_symlink(int sid)
+{
+ scriptitem_T *si = SCRIPT_ITEM(sid);
+ if (si->sn_syml_checked || si->sn_sourced_sid > 0)
+ return;
+ si->sn_syml_checked = TRUE;
+
+ // If fname is a symbolic link, create an script_item for the real file.
+
+ char_u *real_fname = fix_fname(si->sn_name);
+ if (real_fname != NULL && STRCMP(real_fname, si->sn_name) != 0)
+ {
+ int real_sid = find_script_by_name(real_fname);
+ int error2 = OK;
+ int new_sid = FALSE;
+ if (real_sid < 0)
+ {
+ real_sid = get_new_scriptitem_for_fname(&error2, real_fname);
+ new_sid = TRUE;
+ }
+ if (error2 == OK)
+ {
+ si = SCRIPT_ITEM(sid);
+ si->sn_sourced_sid = real_sid;
+ if (new_sid)
+ SCRIPT_ITEM(real_sid)->sn_import_autoload
+ = si->sn_import_autoload;
+ }
+ }
+ vim_free(real_fname);
+}
+
static void
find_script_callback(char_u *fname, void *cookie)
{