@@ -1288,18 +1288,24 @@ int mingw_stat(const char *file_name, struct stat *buf)
12881288 if (hnd == INVALID_HANDLE_VALUE ) {
12891289 DWORD err = GetLastError ();
12901290
1291- if (err == ERROR_ACCESS_DENIED &&
1292- !mingw_lstat (file_name , buf ) &&
1293- !S_ISLNK (buf -> st_mode ))
1294- /*
1295- * POSIX semantics state to still try to fill
1296- * information, even if permission is denied to create
1297- * a file handle.
1298- */
1299- return 0 ;
1291+ /* TODO: special-case existing reparse point and resolve manually if it is a directory */
1292+ if (err != ERROR_ACCESS_DENIED ||
1293+ (hnd = CreateFileW (wfile_name , 0 ,
1294+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
1295+ NULL , OPEN_EXISTING , 0 , NULL )) == INVALID_HANDLE_VALUE ) {
1296+ if (err == ERROR_ACCESS_DENIED &&
1297+ !mingw_lstat (file_name , buf ) &&
1298+ !S_ISLNK (buf -> st_mode ))
1299+ /*
1300+ * POSIX semantics state to still try to fill
1301+ * information, even if permission is denied to create
1302+ * a file handle.
1303+ */
1304+ return 0 ;
13001305
1301- errno = err_win_to_posix (err );
1302- return -1 ;
1306+ errno = err_win_to_posix (err );
1307+ return -1 ;
1308+ }
13031309 }
13041310 result = get_file_info_by_handle (hnd , buf );
13051311 CloseHandle (hnd );
@@ -1512,7 +1518,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
15121518
15131519char * mingw_strbuf_realpath (struct strbuf * resolved , const char * path )
15141520{
1515- wchar_t wpath [MAX_PATH ];
1521+ wchar_t wpath [MAX_PATH ], * p ;
15161522 HANDLE h ;
15171523 DWORD ret ;
15181524 int len ;
@@ -1532,8 +1538,14 @@ char *mingw_strbuf_realpath(struct strbuf *resolved, const char *path)
15321538 */
15331539 if (h == INVALID_HANDLE_VALUE &&
15341540 GetLastError () == ERROR_FILE_NOT_FOUND ) {
1541+ #if 1
1542+ WIN32_FILE_ATTRIBUTE_DATA fdata ;
1543+ if (GetFileAttributesExW (wpath , GetFileExInfoStandard , & fdata ) &&
1544+ fdata .dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT )
1545+ return NULL ; /* must follow symlink */
1546+ #endif
15351547 /* cut last component off of `wpath` */
1536- wchar_t * p = wpath + wcslen (wpath );
1548+ p = wpath + wcslen (wpath );
15371549
15381550 while (p != wpath )
15391551 if (* (-- p ) == L'/' || * p == L'\\' )
0 commit comments