diff --git a/SystemTools.cxx b/SystemTools.cxx index e073cbf911e9dad4e5e66db728c1828bf83952f7..d15fc5d6dc39759a20ee69a7e87c930360c62154 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2804,7 +2804,7 @@ std::string SystemTools::FindProgram(const std::string& name, for (std::string const& ext : extensions) { tryPath = name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2812,7 +2812,7 @@ std::string SystemTools::FindProgram(const std::string& name, #endif // now try just the name - if (SystemTools::FileExists(name, true)) { + if (SystemTools::FileIsExecutable(name)) { return SystemTools::CollapseFullPath(name); } // now construct the path @@ -2842,7 +2842,7 @@ std::string SystemTools::FindProgram(const std::string& name, tryPath = p; tryPath += name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2850,7 +2850,7 @@ std::string SystemTools::FindProgram(const std::string& name, // now try it without them tryPath = p; tryPath += name; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -3005,6 +3005,11 @@ bool SystemTools::FileIsDirectory(const std::string& inName) } } +bool SystemTools::FileIsExecutable(const std::string& name) +{ + return !FileIsDirectory(name) && TestFileAccess(name, TEST_FILE_EXECUTE); +} + bool SystemTools::FileIsSymlink(const std::string& name) { #if defined(_WIN32) @@ -3171,7 +3176,7 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); self = SystemTools::FindProgram(self); - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { if (buildDir) { std::string intdir = "."; #ifdef CMAKE_INTDIR @@ -3186,14 +3191,14 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, } } if (installPrefix) { - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); self = installPrefix; self += "/bin/"; self += exeName; } } - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); std::ostringstream msg; msg << "Can not find the command line program "; diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index d4a93faf7aaa249159864f3d59c8829e4a544e98..0e3ccfc313d27f99b156445d241cfeeaac083a40 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -676,6 +676,11 @@ public: */ static bool FileIsDirectory(const std::string& name); + /** + * Return true if the file is an executable + */ + static bool FileIsExecutable(const std::string& name); + /** * Return true if the file is a symlink */