aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-03-16 19:17:25 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-03-16 19:17:25 +0000
commit3cd0128ce49abe658d1858c541e836e57959e04a (patch)
tree7942a744e6e6d177ff469c9fdf965fcf9a3a40e9 /lib/Basic/FileManager.cpp
parentdb2eae639d3b7ed61ceb56890b73168517ef57f1 (diff)
Having FileManager::getFile always open the file, brought much consternation and leaking of file descriptors.
Add 'openFile' bool to FileManager::getFile to specify whether we want to have the file opened or not, have it false by default, and enable it only in HeaderSearch.cpp where the open+fstat optimization matters. Fixes rdar://9139899. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileManager.cpp')
-rw-r--r--lib/Basic/FileManager.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp
index 9ad6e51a83..1a8b01938e 100644
--- a/lib/Basic/FileManager.cpp
+++ b/lib/Basic/FileManager.cpp
@@ -313,7 +313,7 @@ const DirectoryEntry *FileManager::getDirectory(llvm::StringRef DirName) {
/// getFile - Lookup, cache, and verify the specified file (real or
/// virtual). This returns NULL if the file doesn't exist.
///
-const FileEntry *FileManager::getFile(llvm::StringRef Filename) {
+const FileEntry *FileManager::getFile(llvm::StringRef Filename, bool openFile) {
++NumFileLookups;
// See if there is already an entry in the map.
@@ -354,6 +354,11 @@ const FileEntry *FileManager::getFile(llvm::StringRef Filename) {
return 0;
}
+ if (FileDescriptor != -1 && !openFile) {
+ close(FileDescriptor);
+ FileDescriptor = -1;
+ }
+
// It exists. See if we have already opened a file with the same inode.
// This occurs when one dir is symlinked to another, for example.
FileEntry &UFE = UniqueRealFiles.getFile(InterndFileName, StatBuf);