Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4fc6b6e

Browse files
committed
Fix get_dirent_type() for symlinks on MinGW/MSYS.
On Windows with MSVC, get_dirent_type() was recently made to return DT_LNK for junction points by commit 9d3444d, which fixed some defective dirent.c code. On Windows with Cygwin, get_dirent_type() already worked for symlinks, as it does on POSIX systems, because Cygwin has its own fake symlinks that behave like POSIX (on closer inspection, Cygwin's dirent has the BSD d_type extension but it's probably always DT_UNKNOWN, so we fall back to lstat(), which understands Cygwin symlinks with S_ISLNK()). On Windows with MinGW/MSYS, we need extra code, because the MinGW runtime has its own readdir() without d_type, and the lstat()-based fallback has no knowledge of our convention for treating junctions as symlinks. Back-patch to 14, where get_dirent_type() landed. Reported-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/b9ddf605-6b36-f90d-7c30-7b3e95c46276%40dunslane.net
1 parent 5253519 commit 4fc6b6e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/file_utils.c

+16
Original file line numberDiff line numberDiff line change
@@ -465,5 +465,21 @@ get_dirent_type(const char *path,
465465
#endif
466466
}
467467

468+
#if defined(WIN32) && !defined(_MSC_VER)
469+
470+
/*
471+
* If we're on native Windows (not Cygwin, which has its own POSIX
472+
* symlinks), but not using the MSVC compiler, then we're using a
473+
* readdir() emulation provided by the MinGW runtime that has no d_type.
474+
* Since the lstat() fallback code reports junction points as directories,
475+
* we need an extra system call to check if we should report them as
476+
* symlinks instead, following our convention.
477+
*/
478+
if (result == PGFILETYPE_DIR &&
479+
!look_through_symlinks &&
480+
pgwin32_is_junction(path))
481+
result = PGFILETYPE_LNK;
482+
#endif
483+
468484
return result;
469485
}

0 commit comments

Comments
 (0)