@@ -63,91 +63,16 @@ FileEntry::~FileEntry() {
63
63
if (FD != -1 ) ::close (FD);
64
64
}
65
65
66
- bool FileEntry::isNamedPipe () const {
67
- return S_ISFIFO (FileMode);
68
- }
69
-
70
- // ===----------------------------------------------------------------------===//
71
- // Windows.
72
- // ===----------------------------------------------------------------------===//
73
-
74
- #ifdef LLVM_ON_WIN32
75
-
76
- namespace {
77
- static std::string GetFullPath (const char *relPath) {
78
- char *absPathStrPtr = _fullpath (NULL , relPath, 0 );
79
- assert (absPathStrPtr && " _fullpath() returned NULL!" );
80
-
81
- std::string absPath (absPathStrPtr);
82
-
83
- free (absPathStrPtr);
84
- return absPath;
85
- }
86
- }
87
-
88
- class FileManager ::UniqueDirContainer {
89
- // / UniqueDirs - Cache from full path to existing directories/files.
90
- // /
91
- llvm::StringMap<DirectoryEntry> UniqueDirs;
92
-
93
- public:
94
- // / getDirectory - Return an existing DirectoryEntry with the given
95
- // / name if there is already one; otherwise create and return a
96
- // / default-constructed DirectoryEntry.
97
- DirectoryEntry &getDirectory (const char *Name,
98
- const struct stat & /* StatBuf*/ ) {
99
- std::string FullPath (GetFullPath (Name));
100
- return UniqueDirs.GetOrCreateValue (FullPath).getValue ();
101
- }
102
-
103
- size_t size () const { return UniqueDirs.size (); }
104
- };
105
-
106
- class FileManager ::UniqueFileContainer {
107
- // / UniqueFiles - Cache from full path to existing directories/files.
108
- // /
109
- llvm::StringMap<FileEntry, llvm::BumpPtrAllocator> UniqueFiles;
110
-
111
- public:
112
- // / getFile - Return an existing FileEntry with the given name if
113
- // / there is already one; otherwise create and return a
114
- // / default-constructed FileEntry.
115
- FileEntry &getFile (const char *Name, const struct stat & /* StatBuf*/ ) {
116
- std::string FullPath (GetFullPath (Name));
117
-
118
- // Lowercase string because Windows filesystem is case insensitive.
119
- FullPath = StringRef (FullPath).lower ();
120
- return UniqueFiles.GetOrCreateValue (FullPath).getValue ();
121
- }
122
-
123
- size_t size () const { return UniqueFiles.size (); }
124
-
125
- void erase (const FileEntry *Entry) {
126
- std::string FullPath (GetFullPath (Entry->getName ()));
127
-
128
- // Lowercase string because Windows filesystem is case insensitive.
129
- FullPath = StringRef (FullPath).lower ();
130
- UniqueFiles.erase (FullPath);
131
- }
132
- };
133
-
134
- // ===----------------------------------------------------------------------===//
135
- // Unix-like Systems.
136
- // ===----------------------------------------------------------------------===//
137
-
138
- #else
139
-
140
66
class FileManager ::UniqueDirContainer {
141
67
// / UniqueDirs - Cache from ID's to existing directories/files.
142
- std::map<std::pair< dev_t , ino_t > , DirectoryEntry> UniqueDirs;
68
+ std::map<llvm::sys::fs::UniqueID , DirectoryEntry> UniqueDirs;
143
69
144
70
public:
145
71
// / getDirectory - Return an existing DirectoryEntry with the given
146
72
// / ID's if there is already one; otherwise create and return a
147
73
// / default-constructed DirectoryEntry.
148
- DirectoryEntry &getDirectory (const char * /* Name*/ ,
149
- const struct stat &StatBuf) {
150
- return UniqueDirs[std::make_pair (StatBuf.st_dev , StatBuf.st_ino )];
74
+ DirectoryEntry &getDirectory (const llvm::sys::fs::UniqueID &UniqueID) {
75
+ return UniqueDirs[UniqueID ];
151
76
}
152
77
153
78
size_t size () const { return UniqueDirs.size (); }
@@ -161,21 +86,17 @@ class FileManager::UniqueFileContainer {
161
86
// / getFile - Return an existing FileEntry with the given ID's if
162
87
// / there is already one; otherwise create and return a
163
88
// / default-constructed FileEntry.
164
- FileEntry &getFile (const char * /* Name*/ , const struct stat &StatBuf) {
165
- return
166
- const_cast <FileEntry&>(
167
- *UniqueFiles.insert (FileEntry (StatBuf.st_dev ,
168
- StatBuf.st_ino ,
169
- StatBuf.st_mode )).first );
89
+ FileEntry &getFile (llvm::sys::fs::UniqueID UniqueID, bool IsNamedPipe,
90
+ bool InPCH) {
91
+ return const_cast <FileEntry &>(
92
+ *UniqueFiles.insert (FileEntry (UniqueID , IsNamedPipe, InPCH)).first );
170
93
}
171
94
172
95
size_t size () const { return UniqueFiles.size (); }
173
96
174
97
void erase (const FileEntry *Entry) { UniqueFiles.erase (*Entry); }
175
98
};
176
99
177
- #endif
178
-
179
100
// ===----------------------------------------------------------------------===//
180
101
// Common logic.
181
102
// ===----------------------------------------------------------------------===//
@@ -323,8 +244,8 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
323
244
const char *InterndDirName = NamedDirEnt.getKeyData ();
324
245
325
246
// Check to see if the directory exists.
326
- struct stat StatBuf ;
327
- if (getStatValue (InterndDirName, StatBuf , false , 0 /* directory lookup*/ )) {
247
+ FileData Data ;
248
+ if (getStatValue (InterndDirName, Data , false , 0 /* directory lookup*/ )) {
328
249
// There's no real directory at the given path.
329
250
if (!CacheFailure)
330
251
SeenDirEntries.erase (DirName);
@@ -335,7 +256,8 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
335
256
// same inode (this occurs on Unix-like systems when one dir is
336
257
// symlinked to another, for example) or the same path (on
337
258
// Windows).
338
- DirectoryEntry &UDE = UniqueRealDirs.getDirectory (InterndDirName, StatBuf);
259
+ DirectoryEntry &UDE =
260
+ UniqueRealDirs.getDirectory (Data.UniqueID );
339
261
340
262
NamedDirEnt.setValue (&UDE);
341
263
if (!UDE.getName ()) {
@@ -388,8 +310,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
388
310
389
311
// Nope, there isn't. Check to see if the file exists.
390
312
int FileDescriptor = -1 ;
391
- struct stat StatBuf ;
392
- if (getStatValue (InterndFileName, StatBuf , true ,
313
+ FileData Data ;
314
+ if (getStatValue (InterndFileName, Data , true ,
393
315
openFile ? &FileDescriptor : 0 )) {
394
316
// There's no real file at the given path.
395
317
if (!CacheFailure)
@@ -405,7 +327,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
405
327
406
328
// It exists. See if we have already opened a file with the same inode.
407
329
// This occurs when one dir is symlinked to another, for example.
408
- FileEntry &UFE = UniqueRealFiles.getFile (InterndFileName, StatBuf);
330
+ FileEntry &UFE =
331
+ UniqueRealFiles.getFile (Data.UniqueID , Data.IsNamedPipe , Data.InPCH );
409
332
410
333
NamedFileEnt.setValue (&UFE);
411
334
if (UFE.getName ()) { // Already have an entry with this inode, return it.
@@ -420,8 +343,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
420
343
// FIXME: Change the name to be a char* that points back to the
421
344
// 'SeenFileEntries' key.
422
345
UFE.Name = InterndFileName;
423
- UFE.Size = StatBuf. st_size ;
424
- UFE.ModTime = StatBuf. st_mtime ;
346
+ UFE.Size = Data. Size ;
347
+ UFE.ModTime = Data. ModTime ;
425
348
UFE.Dir = DirInfo;
426
349
UFE.UID = NextFileUID++;
427
350
UFE.FD = FileDescriptor;
@@ -458,12 +381,12 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
458
381
" The directory of a virtual file should already be in the cache." );
459
382
460
383
// Check to see if the file exists. If so, drop the virtual file
461
- struct stat StatBuf ;
384
+ FileData Data ;
462
385
const char *InterndFileName = NamedFileEnt.getKeyData ();
463
- if (getStatValue (InterndFileName, StatBuf , true , 0 ) == 0 ) {
464
- StatBuf. st_size = Size ;
465
- StatBuf. st_mtime = ModificationTime;
466
- UFE = &UniqueRealFiles.getFile (InterndFileName, StatBuf );
386
+ if (getStatValue (InterndFileName, Data , true , 0 ) == 0 ) {
387
+ Data. Size = Size ;
388
+ Data. ModTime = ModificationTime;
389
+ UFE = &UniqueRealFiles.getFile (Data. UniqueID , Data. IsNamedPipe , Data. InPCH );
467
390
468
391
NamedFileEnt.setValue (UFE);
469
392
@@ -572,19 +495,19 @@ getBufferForFile(StringRef Filename, std::string *ErrorStr) {
572
495
// / if the path points to a virtual file or does not exist, or returns
573
496
// / false if it's an existent real file. If FileDescriptor is NULL,
574
497
// / do directory look-up instead of file look-up.
575
- bool FileManager::getStatValue (const char *Path, struct stat &StatBuf ,
576
- bool isFile, int *FileDescriptor) {
498
+ bool FileManager::getStatValue (const char *Path, FileData &Data, bool isFile ,
499
+ int *FileDescriptor) {
577
500
// FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
578
501
// absolute!
579
502
if (FileSystemOpts.WorkingDir .empty ())
580
- return FileSystemStatCache::get (Path, StatBuf , isFile, FileDescriptor,
503
+ return FileSystemStatCache::get (Path, Data , isFile, FileDescriptor,
581
504
StatCache.get ());
582
505
583
506
SmallString<128 > FilePath (Path);
584
507
FixupRelativePath (FilePath);
585
508
586
- return FileSystemStatCache::get (FilePath.c_str (), StatBuf ,
587
- isFile, FileDescriptor, StatCache.get ());
509
+ return FileSystemStatCache::get (FilePath.c_str (), Data, isFile ,
510
+ FileDescriptor, StatCache.get ());
588
511
}
589
512
590
513
bool FileManager::getNoncachedStatValue (StringRef Path,
0 commit comments