mirror of
https://github.com/MaskRay/ccls.git
synced 2025-08-18 04:32:24 +00:00
use realpath(3) to canonicalize file paths on posix
This commit is contained in:
parent
9f25474e73
commit
0b2a9d7b9e
@ -39,9 +39,6 @@ limitations under the License.
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include <llvm/ADT/SmallString.h>
|
||||
#include <llvm/Support/Path.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
@ -52,10 +49,14 @@ namespace pipeline {
|
||||
void ThreadEnter();
|
||||
}
|
||||
|
||||
// Normalize the path, including eliminating redundant . and duplicated /
|
||||
// characters.
|
||||
std::string NormalizePath(const std::string &path) {
|
||||
llvm::SmallString<256> P(path);
|
||||
llvm::sys::path::remove_dots(P, true);
|
||||
return {P.data(), P.size()};
|
||||
char canonical[PATH_MAX + 1];
|
||||
if (realpath(path.c_str(), canonical)) {
|
||||
return canonical;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
void FreeUnusedMemory() {
|
||||
|
@ -125,6 +125,7 @@ void EnsureEndsInSlash(std::string &path) {
|
||||
|
||||
std::string EscapeFileName(std::string path) {
|
||||
bool slash = path.size() && path.back() == '/';
|
||||
path = NormalizePath(path);
|
||||
#ifdef _WIN32
|
||||
std::replace(path.begin(), path.end(), ':', '@');
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user