std::unique_ptr<FileSystemStatCache> StatCache;
bool getStatValue(const char *Path, FileData &Data, bool isFile,
- vfs::File **F);
+ std::unique_ptr<vfs::File> *F);
/// Add all ancestors of the given path (pointing to either a file
/// or a directory) as virtual directories.
/// implementation can optionally fill in \p F with a valid \p File object and
/// the client guarantees that it will close it.
static bool get(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, FileSystemStatCache *Cache,
+ std::unique_ptr<vfs::File> *F, FileSystemStatCache *Cache,
vfs::FileSystem &FS);
/// \brief Sets the next stat call cache in the chain of stat caches.
FileSystemStatCache *takeNextStatCache() { return NextStatCache.release(); }
protected:
+ // FIXME: The pointer here is a non-owning/optional reference to the
+ // unique_ptr. Optional<unique_ptr<vfs::File>&> might be nicer, but
+ // Optional needs some work to support references so this isn't possible yet.
virtual LookupResult getStat(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) = 0;
+ std::unique_ptr<vfs::File> *F,
+ vfs::FileSystem &FS) = 0;
LookupResult statChained(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) {
+ std::unique_ptr<vfs::File> *F, vfs::FileSystem &FS) {
if (FileSystemStatCache *Next = getNextStatCache())
return Next->getStat(Path, Data, isFile, F, FS);
iterator end() const { return StatCalls.end(); }
LookupResult getStat(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) override;
+ std::unique_ptr<vfs::File> *F,
+ vfs::FileSystem &FS) override;
};
} // end namespace clang
// FIXME: This will reduce the # syscalls.
// Nope, there isn't. Check to see if the file exists.
- vfs::File *F = nullptr;
+ std::unique_ptr<vfs::File> F;
FileData Data;
if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
// There's no real file at the given path.
if (DirInfo != UFE.Dir && Data.IsVFSMapped)
UFE.Dir = DirInfo;
- // If the stat process opened the file, close it to avoid a FD leak.
- if (F)
- delete F;
-
return &UFE;
}
UFE.UniqueID = Data.UniqueID;
UFE.IsNamedPipe = Data.IsNamedPipe;
UFE.InPCH = Data.InPCH;
- UFE.File.reset(F);
+ UFE.File = std::move(F);
UFE.IsValid = true;
return &UFE;
}
/// false if it's an existent real file. If FileDescriptor is NULL,
/// do directory look-up instead of file look-up.
bool FileManager::getStatValue(const char *Path, FileData &Data, bool isFile,
- vfs::File **F) {
+ std::unique_ptr<vfs::File> *F) {
// FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
// absolute!
if (FileSystemOpts.WorkingDir.empty())
/// 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, FileData &Data, bool isFile,
- vfs::File **F, FileSystemStatCache *Cache,
- vfs::FileSystem &FS) {
+ std::unique_ptr<vfs::File> *F,
+ FileSystemStatCache *Cache, vfs::FileSystem &FS) {
LookupResult R;
bool isForDir = !isFile;
if (Status) {
R = CacheExists;
copyStatusToFileData(*Status, Data);
- *F = OwnedFile.release();
+ *F = std::move(OwnedFile);
} else {
// fstat rarely fails. If it does, claim the initial open didn't
// succeed.
// demands.
if (Data.IsDirectory != isForDir) {
// If not, close the file if opened.
- if (F && *F) {
- (*F)->close();
- delete *F;
+ if (F)
*F = nullptr;
- }
return true;
}
MemorizeStatCalls::LookupResult
MemorizeStatCalls::getStat(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) {
+ std::unique_ptr<vfs::File> *F, vfs::FileSystem &FS) {
LookupResult Result = statChained(Path, Data, isFile, F, FS);
// Do not cache failed stats, it is easy to construct common inconsistent
~StatListener() {}
LookupResult getStat(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) override {
+ std::unique_ptr<vfs::File> *F,
+ vfs::FileSystem &FS) override {
LookupResult Result = statChained(Path, Data, isFile, F, FS);
if (Result == CacheMissing) // Failed 'stat'.
Cache(FL.getNumBuckets(), FL.getNumEntries(), FL.getBuckets(),
FL.getBase()) {}
- ~PTHStatCache() {}
-
LookupResult getStat(const char *Path, FileData &Data, bool isFile,
- vfs::File **F, vfs::FileSystem &FS) override {
+ std::unique_ptr<vfs::File> *F,
+ vfs::FileSystem &FS) override {
// Do the lookup for the file's data in the PTH file.
CacheTy::iterator I = Cache.find(Path);