Skip to content

Commit fce7b3d

Browse files
committed
patch 7.4.1139
Problem: MS-Windows: getftype() returns "file for symlink to directory. Solution: Make it return "dir". (Ken Takata)
1 parent 3a466a8 commit fce7b3d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/os_mswin.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,16 @@ slash_adjust(p)
506506
static int
507507
stat_symlink_aware(const char *name, struct stat *stp)
508508
{
509-
#if defined(_MSC_VER) && _MSC_VER < 1700
510-
/* Work around for VC10 or earlier. stat() can't handle symlinks properly.
509+
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__)
510+
/* Work around for VC12 or earlier (and MinGW). stat() can't handle
511+
* symlinks properly.
511512
* VC9 or earlier: stat() doesn't support a symlink at all. It retrieves
512513
* status of a symlink itself.
513514
* VC10: stat() supports a symlink to a normal file, but it doesn't support
514-
* a symlink to a directory (always returns an error). */
515+
* a symlink to a directory (always returns an error).
516+
* VC11 and VC12: stat() doesn't return an error for a symlink to a
517+
* directory, but it doesn't set S_IFDIR flag.
518+
* MinGW: Same as VC9. */
515519
WIN32_FIND_DATA findData;
516520
HANDLE hFind, h;
517521
DWORD attr = 0;
@@ -540,6 +544,8 @@ stat_symlink_aware(const char *name, struct stat *stp)
540544

541545
fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY);
542546
n = _fstat(fd, (struct _stat*)stp);
547+
if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY))
548+
stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR;
543549
_close(fd);
544550
return n;
545551
}
@@ -552,12 +558,16 @@ stat_symlink_aware(const char *name, struct stat *stp)
552558
static int
553559
wstat_symlink_aware(const WCHAR *name, struct _stat *stp)
554560
{
555-
# if defined(_MSC_VER) && _MSC_VER < 1700
556-
/* Work around for VC10 or earlier. _wstat() can't handle symlinks properly.
561+
# if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__)
562+
/* Work around for VC12 or earlier (and MinGW). _wstat() can't handle
563+
* symlinks properly.
557564
* VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves
558565
* status of a symlink itself.
559566
* VC10: _wstat() supports a symlink to a normal file, but it doesn't
560-
* support a symlink to a directory (always returns an error). */
567+
* support a symlink to a directory (always returns an error).
568+
* VC11 and VC12: _wstat() doesn't return an error for a symlink to a
569+
* directory, but it doesn't set S_IFDIR flag.
570+
* MinGW: Same as VC9. */
561571
int n;
562572
BOOL is_symlink = FALSE;
563573
HANDLE hFind, h;
@@ -587,6 +597,8 @@ wstat_symlink_aware(const WCHAR *name, struct _stat *stp)
587597

588598
fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY);
589599
n = _fstat(fd, stp);
600+
if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY))
601+
stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR;
590602
_close(fd);
591603
return n;
592604
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1139,
744746
/**/
745747
1138,
746748
/**/

0 commit comments

Comments
 (0)