diff options
author | Brad King <brad.king@kitware.com> | 2022-06-23 13:38:08 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-06-23 13:38:26 (GMT) |
commit | 10c2bb626ecc82b2307691847d347c03835d7bcc (patch) | |
tree | b4ebd8c8b0253406d7fe08cc57b66ce2ba8ff05c | |
parent | 71a6982e910eabab5329a038972a671c154226c6 (diff) | |
parent | db19b7a73fdae98994bc59554abd02728ecb56a7 (diff) | |
download | CMake-10c2bb626ecc82b2307691847d347c03835d7bcc.zip CMake-10c2bb626ecc82b2307691847d347c03835d7bcc.tar.gz CMake-10c2bb626ecc82b2307691847d347c03835d7bcc.tar.bz2 |
Merge topic 'update-kwsys'
db19b7a73f Merge branch 'upstream-KWSys' into update-kwsys
02dbf65dee KWSys 2022-06-21 (d427a180)
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7403
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 5889a4b..89a3cc7 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -3067,17 +3067,14 @@ std::string SystemTools::GetRealPath(const std::string& path, return ret; } -bool SystemTools::FileIsDirectory(const std::string& inName) +// Remove any trailing slash from the name except in a root component. +static const char* RemoveTrailingSlashes( + const std::string& inName, char (&local_buffer)[KWSYS_SYSTEMTOOLS_MAXPATH], + std::string& string_buffer) { - if (inName.empty()) { - return false; - } size_t length = inName.size(); const char* name = inName.c_str(); - // Remove any trailing slash from the name except in a root component. - char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; - std::string string_buffer; size_t last = length - 1; if (last > 0 && (name[last] == '/' || name[last] == '\\') && strcmp(name, "/") != 0 && name[last - 1] != ':') { @@ -3091,6 +3088,19 @@ bool SystemTools::FileIsDirectory(const std::string& inName) } } + return name; +} + +bool SystemTools::FileIsDirectory(const std::string& inName) +{ + if (inName.empty()) { + return false; + } + + char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; + std::string string_buffer; + const auto name = RemoveTrailingSlashes(inName, local_buffer, string_buffer); + // Now check the file node type. #if defined(_WIN32) DWORD attr = @@ -3107,9 +3117,21 @@ bool SystemTools::FileIsDirectory(const std::string& inName) } } -bool SystemTools::FileIsExecutable(const std::string& name) +bool SystemTools::FileIsExecutable(const std::string& inName) { - return !FileIsDirectory(name) && TestFileAccess(name, TEST_FILE_EXECUTE); +#ifdef _WIN32 + char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; + std::string string_buffer; + const auto name = RemoveTrailingSlashes(inName, local_buffer, string_buffer); + const auto attr = + GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str()); + + // On Windows any file that exists and is not a directory is considered + // readable and therefore also executable: + return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY); +#else + return !FileIsDirectory(inName) && TestFileAccess(inName, TEST_FILE_EXECUTE); +#endif } #if defined(_WIN32) |