From b671a59da80fa1db6115e3275149f9639681453a Mon Sep 17 00:00:00 2001
From: Jeremy Drake <github@jdrake.com>
Date: Thu, 22 Jul 2021 11:59:16 -0700
Subject: [PATCH 48/N] Cygwin: make option for native inner link handling.

This code has been causing issues with SUBST and mapped network drives,
so add an option (defaulted to on) which can be used to disable it where
needed.  MSYS=nonativeinnerlinks
---
 winsup/cygwin/environ.cc | 1 +
 winsup/cygwin/globals.cc | 1 +
 winsup/cygwin/path.cc    | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index e1dbba3..91e3e9c 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -127,6 +127,7 @@ static struct parse_thing
   {"disable_pcon", {&disable_pcon}, setbool, NULL, {{false}, {true}}},
   {"enable_pcon", {&disable_pcon}, setnegbool, NULL, {{true}, {false}}},
   {"winjitdebug", {&winjitdebug}, setbool, NULL, {{false}, {true}}},
+  {"nativeinnerlinks", {&nativeinnerlinks}, setbool, NULL, {{false}, {true}}},
   {NULL, {0}, setdword, 0, {{0}, {0}}}
 };
 
diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc
index a729e70..a144a98 100644
--- a/winsup/cygwin/globals.cc
+++ b/winsup/cygwin/globals.cc
@@ -75,6 +75,7 @@ bool wincmdln = true;
 winsym_t allow_winsymlinks = WSYM_deepcopy;
 bool disable_pcon = true;
 bool winjitdebug = false;
+bool nativeinnerlinks = true;
 
 bool NO_COPY in_forkee;
 
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 67124bb..2cf8c93 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3641,7 +3641,8 @@ restart:
 	    goto file_not_symlink;
 	}
 #endif /* __i386__ */
-      if ((pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
+      if (nativeinnerlinks
+	  && (pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW)
 	{
 	  PWCHAR fpbuf = tp.w_get ();
 	  DWORD ret;
-- 
2.32.0.windows.2

