Skip to content

Commit 452dde5

Browse files
fix: Tighten in-project check for files in build root (#352)
1 parent eab3662 commit 452dde5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

indexer/IdPathMappings.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "absl/functional/function_ref.h"
77

88
#include "clang/Basic/SourceLocation.h"
9+
#include "llvm/Support/FileSystem.h"
910

1011
#include "indexer/FileMetadata.h"
1112
#include "indexer/Hash.h"
@@ -106,9 +107,14 @@ bool FileMetadataMap::insert(clang::FileID fileId, AbsolutePathRef absPathRef) {
106107
auto originalFileSourcePath =
107108
this->projectRootPath.makeAbsoluteAllowKindMismatch(
108109
buildRootRelPath.value());
109-
std::error_code error{};
110-
if (std::filesystem::exists(originalFileSourcePath.asStringRef(), error)
111-
&& !error) {
110+
llvm::SmallString<64> realPath{};
111+
std::error_code error = llvm::sys::fs::real_path(
112+
originalFileSourcePath.asStringRef(), realPath);
113+
// It is possible using symlinks for there to be the situation that
114+
// projectRoot / relativePath exists, but is actually a symlink to
115+
// inside the build root, rather than an in-project file. So check that
116+
// that real_path is the same.
117+
if (!error && realPath.str() == originalFileSourcePath.asStringRef()) {
112118
return insertRelPath(RootRelativePathRef(buildRootRelPath->asStringView(),
113119
RootKind::Project),
114120
/*isInProject*/ true);

0 commit comments

Comments
 (0)