diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-23 21:17:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-23 21:17:56 +0000 |
commit | 898a061f69e1145bf89a987c08203132b9922a3c (patch) | |
tree | bde19ba5ef8b70e02451772ced8e6d09920ee4e0 /lib/Basic/FileSystemStatCache.cpp | |
parent | f9f7766846a205bc900b578f944567e679b221aa (diff) |
change the 'is directory' indicator to be a null-or-not
pointer that is passed down through the APIs, and make
FileSystemStatCache::get be the one that filters out
directory lookups that hit files. This also paves the
way to have stat queries be able to return opened files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileSystemStatCache.cpp')
-rw-r--r-- | lib/Basic/FileSystemStatCache.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/Basic/FileSystemStatCache.cpp b/lib/Basic/FileSystemStatCache.cpp index 6457414df9..b2d43e4744 100644 --- a/lib/Basic/FileSystemStatCache.cpp +++ b/lib/Basic/FileSystemStatCache.cpp @@ -19,9 +19,35 @@ using namespace clang; #define S_ISDIR(s) (_S_IFDIR & s) #endif +/// FileSystemStatCache::get - Get the 'stat' information for the specified +/// path, using the cache to accellerate it if possible. This returns true if +/// the path does not exist or false if it exists. +/// +/// If FileDescriptor is non-null, then this lookup should only return success +/// for files (not directories). If it is null this lookup should only return +/// success for directories (not files). On a successful file lookup, the +/// implementation can optionally fill in FileDescriptor with a valid +/// descriptor and the client guarantees that it will close it. +bool FileSystemStatCache::get(const char *Path, struct stat &StatBuf, + int *FileDescriptor, FileSystemStatCache *Cache) { + LookupResult R; + + if (Cache) + R = Cache->getStat(Path, StatBuf, FileDescriptor); + else + R = ::stat(Path, &StatBuf) != 0 ? CacheMissing : CacheExists; + + if (R == CacheMissing) return true; + + bool isForDir = FileDescriptor == 0; + return S_ISDIR(StatBuf.st_mode) != isForDir; +} + + MemorizeStatCalls::LookupResult -MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) { - LookupResult Result = statChained(Path, StatBuf); +MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf, + int *FileDescriptor) { + LookupResult Result = statChained(Path, StatBuf, FileDescriptor); // Do not cache failed stats, it is easy to construct common inconsistent // situations if we do, and they are not important for PCH performance (which |