diff options
author | KWSys Upstream <kwrobot@kitware.com> | 2018-08-07 11:15:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-08-07 11:16:04 (GMT) |
commit | 4d76239a5107c0eb63486d948ae862784cfc6f9b (patch) | |
tree | 79cd3efef0c0158b7211a1263dd2a3937def3dfc | |
parent | c454a1435ab8d1c167908abb918a756d2f0da058 (diff) | |
download | CMake-4d76239a5107c0eb63486d948ae862784cfc6f9b.zip CMake-4d76239a5107c0eb63486d948ae862784cfc6f9b.tar.gz CMake-4d76239a5107c0eb63486d948ae862784cfc6f9b.tar.bz2 |
KWSys 2018-08-07 (9044518f)
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 9044518f428b84da70f1e02d09b7cd4c35366831 (master).
Upstream Shortlog
-----------------
Jon Chronopoulos (1):
55a29eba SystemTools: Allow FileExists on Windows to follow symlinks
-rw-r--r-- | SystemTools.cxx | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx index d552d9f..476fe08 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -1197,9 +1197,27 @@ bool SystemTools::FileExists(const std::string& filename) } return access(filename.c_str(), R_OK) == 0; #elif defined(_WIN32) - return ( - GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()) != - INVALID_FILE_ATTRIBUTES); + DWORD attr = + GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()); + if (attr == INVALID_FILE_ATTRIBUTES) { + return false; + } + + if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { + // Using 0 instead of GENERIC_READ as it allows reading of file attributes + // even if we do not have permission to read the file itself + HANDLE handle = + CreateFileW(Encoding::ToWindowsExtendedPath(filename).c_str(), 0, 0, + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + + if (handle == INVALID_HANDLE_VALUE) { + return false; + } + + CloseHandle(handle); + } + + return true; #else // SCO OpenServer 5.0.7/3.2's command has 711 permission. # if defined(_SCO_DS) |