File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 49
49
#include < limits>
50
50
#include < map>
51
51
#include < memory>
52
+ #include < mutex>
52
53
#include < string>
53
54
#include < system_error>
54
55
#include < utility>
@@ -244,6 +245,9 @@ class RealFileSystem : public FileSystem {
244
245
std::error_code setCurrentWorkingDirectory (const Twine &Path) override ;
245
246
std::error_code getRealPath (const Twine &Path,
246
247
SmallVectorImpl<char > &Output) const override ;
248
+ private:
249
+ mutable std::mutex CWDMutex;
250
+ mutable std::string CWDCache;
247
251
};
248
252
249
253
} // namespace
@@ -266,10 +270,14 @@ RealFileSystem::openFileForRead(const Twine &Name) {
266
270
}
267
271
268
272
llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory () const {
273
+ std::lock_guard<std::mutex> Lock (CWDMutex);
274
+ if (!CWDCache.empty ())
275
+ return CWDCache;
269
276
SmallString<256 > Dir;
270
277
if (std::error_code EC = llvm::sys::fs::current_path (Dir))
271
278
return EC;
272
- return Dir.str ().str ();
279
+ CWDCache = Dir.str ();
280
+ return CWDCache;
273
281
}
274
282
275
283
std::error_code RealFileSystem::setCurrentWorkingDirectory (const Twine &Path) {
@@ -280,7 +288,13 @@ std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
280
288
// difference for example on network filesystems, where symlinks might be
281
289
// switched during runtime of the tool. Fixing this depends on having a
282
290
// file system abstraction that allows openat() style interactions.
283
- return llvm::sys::fs::set_current_path (Path);
291
+ if (auto EC = llvm::sys::fs::set_current_path (Path))
292
+ return EC;
293
+
294
+ // Invalidate cache.
295
+ std::lock_guard<std::mutex> Lock (CWDMutex);
296
+ CWDCache.clear ();
297
+ return std::error_code ();
284
298
}
285
299
286
300
std::error_code
You can’t perform that action at this time.
0 commit comments