[llvm] r184074 - Fix incorrectly finding 'executable' directories instead of files.
Manuel Klimek
klimek at google.com
Mon Jun 17 03:48:36 PDT 2013
Author: klimek
Date: Mon Jun 17 05:48:34 2013
New Revision: 184074
URL: http://llvm.org/viewvc/llvm-project?rev=184074&view=rev
Log:
Fix incorrectly finding 'executable' directories instead of files.
This broke for example the 'not' utility, if a directory called
'FileCheck' is executable and in the path before the actual 'FileCheck'.
This patch steals the implementation of the "old" PathV1 canExecute
implementation:
- checks for R_OK (file readable): this is necessary for executing
scripts; we should not regress here unless we have good reasons
- checks for S_ISREG; if we want to get rid of this, we'd need to
change all callers who already made the assumption when depending
on Path V1.
Modified:
llvm/trunk/lib/Support/Unix/PathV2.inc
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=184074&r1=184073&r2=184074&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Mon Jun 17 05:48:34 2013
@@ -296,7 +296,14 @@ bool can_execute(const Twine &Path) {
SmallString<128> PathStorage;
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
- return ::access(P.begin(), X_OK) != -1;
+ if (0 != access(P.begin(), R_OK | X_OK))
+ return false;
+ struct stat buf;
+ if (0 != stat(P.begin(), &buf))
+ return false;
+ if (!S_ISREG(buf.st_mode))
+ return false;
+ return true;
}
bool equivalent(file_status A, file_status B) {
More information about the llvm-commits
mailing list