In MSYS2 <-> MINGW transitions, we convert a couple of environment variables between Unix and Windows styles, most notably `PATH`. In the Git for Windows project, we realized that the environment variables `SHELL` and `ORIGINAL_PATH` need the same treatment. These patches have proved their worth for years, and it is time for them to be integrated back into the actual MSYS2 runtime. This should fix https://github.com/msys2/msys2-runtime/issues/43. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
86 lines
3.0 KiB
Diff
86 lines
3.0 KiB
Diff
From 2480c0e3242665890e1dac01891c5a7834fdd138 Mon Sep 17 00:00:00 2001
|
|
From: Takashi Yano <takashi.yano@nifty.ne.jp>
|
|
Date: Thu, 9 Dec 2021 17:15:23 +0900
|
|
Subject: [PATCH 37/N] Cygwin: path: Fix path conversion of virtual drive.
|
|
|
|
- The last change in path.cc introduced a bug that causes an error
|
|
when accessing a virtual drive which mounts UNC path such as
|
|
"\\server\share\dir" rather than "\\server\share". This patch
|
|
fixes the issue.
|
|
---
|
|
winsup/cygwin/path.cc | 56 +++++++++++++++++++++++++++----------------
|
|
1 file changed, 35 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
|
|
index 06b26d2..36f15bd 100644
|
|
--- a/winsup/cygwin/path.cc
|
|
+++ b/winsup/cygwin/path.cc
|
|
@@ -3670,29 +3670,43 @@ restart:
|
|
if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE)
|
|
&& !RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
|
|
{
|
|
- /* ...get the remote path from the volume path name,
|
|
- replace remote path with drive letter, check again. */
|
|
+ /* ...get the remote path, replace remote path
|
|
+ with drive letter, check again. */
|
|
+ WCHAR drive[3] =
|
|
+ {(WCHAR) towupper (upath.Buffer[4]), L':', L'\0'};
|
|
WCHAR remote[MAX_PATH];
|
|
|
|
- fpbuf[1] = L'\\';
|
|
- BOOL r = GetVolumePathNameW (fpbuf, remote, MAX_PATH);
|
|
- fpbuf[1] = L'?';
|
|
- if (r)
|
|
- {
|
|
- int remlen = wcslen (remote);
|
|
- if (remote[remlen - 1] == L'\\')
|
|
- remlen--;
|
|
- /* Hackfest */
|
|
- fpath.Buffer[4] = upath.Buffer[4]; /* Drive letter */
|
|
- fpath.Buffer[5] = L':';
|
|
- WCHAR *to = fpath.Buffer + 6;
|
|
- WCHAR *from = to + remlen - 6;
|
|
- memmove (to, from,
|
|
- (wcslen (from) + 1) * sizeof (WCHAR));
|
|
- fpath.Length -= (from - to) * sizeof (WCHAR);
|
|
- if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
|
|
- goto file_not_symlink;
|
|
- }
|
|
+
|
|
+ int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
|
|
+ if (remlen < 3)
|
|
+ goto file_not_symlink; /* fallback */
|
|
+ remlen -= 2;
|
|
+
|
|
+ if (remote[remlen - 1] == L'\\')
|
|
+ remlen--;
|
|
+ WCHAR *p;
|
|
+ UNICODE_STRING rpath;
|
|
+ RtlInitCountedUnicodeString (&rpath, remote,
|
|
+ remlen * sizeof (WCHAR));
|
|
+ if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
|
|
+ remlen -= 6;
|
|
+ else if ((p = wcschr (remote, L';'))
|
|
+ && p + 3 < remote + remlen
|
|
+ && wcsncmp (p + 1, drive, 2) == 0
|
|
+ && (p = wcschr (p + 3, L'\\')))
|
|
+ remlen -= p - remote - 1;
|
|
+ else
|
|
+ goto file_not_symlink; /* fallback */
|
|
+ /* Hackfest */
|
|
+ fpath.Buffer[4] = drive[0]; /* Drive letter */
|
|
+ fpath.Buffer[5] = L':';
|
|
+ WCHAR *to = fpath.Buffer + 6;
|
|
+ WCHAR *from = to + remlen;
|
|
+ memmove (to, from,
|
|
+ (wcslen (from) + 1) * sizeof (WCHAR));
|
|
+ fpath.Length -= (from - to) * sizeof (WCHAR);
|
|
+ if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
|
|
+ goto file_not_symlink;
|
|
}
|
|
issymlink = true;
|
|
/* upath.Buffer is big enough and unused from this point on.
|
|
--
|
|
2.34.1
|
|
|