mirror of
https://github.com/MaskRay/ccls.git
synced 2025-08-20 05:32:23 +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>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <llvm/ADT/SmallString.h>
|
|
||||||
#include <llvm/Support/Path.h>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -52,10 +49,14 @@ namespace pipeline {
|
|||||||
void ThreadEnter();
|
void ThreadEnter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize the path, including eliminating redundant . and duplicated /
|
||||||
|
// characters.
|
||||||
std::string NormalizePath(const std::string &path) {
|
std::string NormalizePath(const std::string &path) {
|
||||||
llvm::SmallString<256> P(path);
|
char canonical[PATH_MAX + 1];
|
||||||
llvm::sys::path::remove_dots(P, true);
|
if (realpath(path.c_str(), canonical)) {
|
||||||
return {P.data(), P.size()};
|
return canonical;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeUnusedMemory() {
|
void FreeUnusedMemory() {
|
||||||
|
@ -125,6 +125,7 @@ void EnsureEndsInSlash(std::string &path) {
|
|||||||
|
|
||||||
std::string EscapeFileName(std::string path) {
|
std::string EscapeFileName(std::string path) {
|
||||||
bool slash = path.size() && path.back() == '/';
|
bool slash = path.size() && path.back() == '/';
|
||||||
|
path = NormalizePath(path);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::replace(path.begin(), path.end(), ':', '@');
|
std::replace(path.begin(), path.end(), ':', '@');
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user