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 | dd278430a387f1dd916618c3a1b90c14c0064973 (patch) | |
tree | 5aaf703e2c6f7b4284f7e4e9ab54771f55bff513 /clang/lib/Basic/FileSystemStatCache.cpp | |
parent | 5aef638057816ef414bb6adde40eafafec78e1d3 (diff) | |
download | bcm5719-llvm-dd278430a387f1dd916618c3a1b90c14c0064973.tar.gz bcm5719-llvm-dd278430a387f1dd916618c3a1b90c14c0064973.zip |
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.
llvm-svn: 120060
Diffstat (limited to 'clang/lib/Basic/FileSystemStatCache.cpp')
-rw-r--r-- | clang/lib/Basic/FileSystemStatCache.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/clang/lib/Basic/FileSystemStatCache.cpp b/clang/lib/Basic/FileSystemStatCache.cpp index 6457414df98..b2d43e47447 100644 --- a/clang/lib/Basic/FileSystemStatCache.cpp +++ b/clang/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 |