Skip to content

Commit f3151fe

Browse files
bmueller84dscho
authored andcommitted
mingw: fix fatal error working on mapped network drives on Windows
In 1e64d18 (mingw: do resolve symlinks in `getcwd()`) a problem was introduced that causes git for Windows to stop working with certain mapped network drives (in particular, drives that are mapped to locations with long path names). Error message was "fatal: Unable to read current working directory: No such file or directory". Present change fixes this issue as discussed in #2480 Signed-off-by: Bjoern Mueller <[email protected]>
1 parent 3088b34 commit f3151fe

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compat/mingw.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,13 @@ char *mingw_getcwd(char *pointer, int len)
11561156
return NULL;
11571157
ret = GetFinalPathNameByHandleW(hnd, wpointer, ARRAY_SIZE(wpointer), 0);
11581158
CloseHandle(hnd);
1159-
if (!ret || ret >= ARRAY_SIZE(wpointer))
1160-
return NULL;
1159+
if (!ret || ret >= ARRAY_SIZE(wpointer)) {
1160+
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
1161+
if (!ret || ret >= ARRAY_SIZE(wpointer)) {
1162+
errno = ret ? ENAMETOOLONG : err_win_to_posix(GetLastError());
1163+
return NULL;
1164+
}
1165+
}
11611166
if (xwcstoutf(pointer, normalize_ntpath(wpointer), len) < 0)
11621167
return NULL;
11631168
return pointer;

0 commit comments

Comments
 (0)