[PATCH] D51159: [FileManager] Do not call 'real_path' in getFile().
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 23 10:51:42 PDT 2018
ioeric added inline comments.
================
Comment at: lib/Basic/FileManager.cpp:319
- SmallString<128> RealPathName;
- if (!FS->getRealPath(InterndFileName, RealPathName))
- UFE.RealPathName = RealPathName.str();
+ if (UFE.File) {
+ if (auto Path = UFE.File->getName()) {
----------------
simark wrote:
> What's the rationale for only computing the field if `UFE.File` is non-null?
>
> Previously, if you looked up the file with `openFile == false` and then later `openFile == true`, the `RealPathName` field would not be set because of this. That doesn't seem right.
There has been no guarantee that RealFilePath is always set. I think that's the reason why the acceasor is called tryGetRealPathName.
================
Comment at: lib/Basic/FileManager.cpp:326
+ llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
+ UFE.RealPathName = AbsPath.str();
+ }
----------------
simark wrote:
> If the path contains symlinks, doesn't this put a non-real path in the RealPathName field? Won't users (e.g. clangd) use this value thinking it is a real path, when it is actually not?
This was the original behavior. In general, File Manager should never call real_path for users because it can be very expensive. Users should call real_path if they want to resolve symlinks. That said, it's fair to say that "RealPathName" is just a wrong name, and we should clean it up at some point.
Repository:
rC Clang
https://reviews.llvm.org/D51159
More information about the cfe-commits
mailing list