fix index error when there is a soft link file as https://github.com/MaskRay/ccls/pull/643

This commit is contained in:
lenajin 2020-06-28 11:26:33 +08:00
parent 8cf8a3c4a4
commit 88cd914342

View File

@ -25,6 +25,7 @@
#include <inttypes.h>
#include <map>
#include <unordered_set>
#include <filesystem>
using namespace clang;
@ -1355,6 +1356,11 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
return {};
}
std::string abs_main;
if (std::filesystem::exists(main)) {
abs_main = std::filesystem::canonical(main);
}
std::vector<std::unique_ptr<IndexFile>> result;
for (auto &it : param.uid2file) {
if (!it.second.db)
@ -1392,6 +1398,13 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
entry->dependencies[llvm::CachedHashStringRef(intern(path))] =
file.mtime;
}
std::string abs_entry;
if (std::filesystem::exists(entry->path)) {
abs_entry = std::filesystem::canonical(entry->path);
if (abs_entry == abs_main){
entry->path = main;
}
}
result.push_back(std::move(entry));
}