patch 9.0.1769: executable() ignoring symlinks on Windows
Problem: executable() ignoring symlinks on Windows
Solution: resolve reparse points
closes: #12562
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: AmberArr <me@frost.moe>
diff --git a/src/os_mswin.c b/src/os_mswin.c
index 5360fa9..aa5fe52 100644
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -1775,7 +1775,11 @@
return FALSE;
}
- static char_u *
+/*
+ * Return the resolved file path, NULL if "fname" is an AppExecLink reparse
+ * point, already fully resolved, or it doesn't exists.
+ */
+ char_u *
resolve_reparse_point(char_u *fname)
{
HANDLE h = INVALID_HANDLE_VALUE;
diff --git a/src/os_win32.c b/src/os_win32.c
index 52e0583..ff60e04 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -2721,6 +2721,8 @@
{
char_u *res = resolve_appexeclink((char_u *)name);
if (res == NULL)
+ res = resolve_reparse_point((char_u *)name);
+ if (res == NULL)
return FALSE;
// The path is already absolute.
if (path != NULL)
diff --git a/src/proto/os_mswin.pro b/src/proto/os_mswin.pro
index c63129f..d9172ee 100644
--- a/src/proto/os_mswin.pro
+++ b/src/proto/os_mswin.pro
@@ -37,6 +37,7 @@
void mch_print_set_font(int iBold, int iItalic, int iUnderline);
void mch_print_set_bg(long_u bgcol);
void mch_print_set_fg(long_u fgcol);
+char_u *resolve_reparse_point(char_u *fname);
char_u *mch_resolve_path(char_u *fname, int reparse_point);
void win32_set_foreground(void);
void serverInitMessaging(void);
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 60e9921..a500b73 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -1818,6 +1818,10 @@
let [pathext, $PATHEXT] = [$PATHEXT, '.com;.exe;.bat;.cmd']
call assert_equal(notepadbat, exepath('notepad'))
let $PATHEXT = pathext
+ " check for symbolic link
+ execute 'silent !mklink np.bat "' .. notepadbat .. '"'
+ call assert_equal(1, executable('./np.bat'))
+ call assert_equal(1, executable('./np'))
bwipe
eval 'Xnotedir'->delete('rf')
elseif has('unix')
diff --git a/src/version.c b/src/version.c
index 598e3ee..e81dd71 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1769,
+/**/
1768,
/**/
1767,