summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r--clang/lib/Basic/FileManager.cpp35
-rw-r--r--clang/lib/Basic/VirtualFileSystem.cpp4
2 files changed, 3 insertions, 36 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 21e6ea3ab4b..8a523d26dec 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -526,39 +526,6 @@ void FileManager::modifyFileEntry(FileEntry *File,
File->ModTime = ModificationTime;
}
-/// Remove '.' and '..' path components from the given absolute path.
-/// \return \c true if any changes were made.
-// FIXME: Move this to llvm::sys::path.
-bool FileManager::removeDotPaths(SmallVectorImpl<char> &Path, bool RemoveDotDot) {
- using namespace llvm::sys;
-
- SmallVector<StringRef, 16> ComponentStack;
- StringRef P(Path.data(), Path.size());
-
- // Skip the root path, then look for traversal in the components.
- StringRef Rel = path::relative_path(P);
- for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
- if (C == ".")
- continue;
- if (RemoveDotDot) {
- if (C == "..") {
- if (!ComponentStack.empty())
- ComponentStack.pop_back();
- continue;
- }
- }
- ComponentStack.push_back(C);
- }
-
- SmallString<256> Buffer = path::root_path(P);
- for (StringRef C : ComponentStack)
- path::append(Buffer, C);
-
- bool Changed = (Path != Buffer);
- Path.swap(Buffer);
- return Changed;
-}
-
StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
// FIXME: use llvm::sys::fs::canonical() when it gets implemented
llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
@@ -582,7 +549,7 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
// '..' is pretty safe.
// Ideally we'd have an equivalent of `realpath` and could implement
// sys::fs::canonical across all the platforms.
- removeDotPaths(CanonicalNameBuf, /*RemoveDotDot*/true);
+ llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true);
CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
#endif
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp
index a20132b3de8..8acf0a997d5 100644
--- a/clang/lib/Basic/VirtualFileSystem.cpp
+++ b/clang/lib/Basic/VirtualFileSystem.cpp
@@ -499,7 +499,7 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
(void)EC;
if (useNormalizedPaths())
- FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+ llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
if (Path.empty())
return false;
@@ -572,7 +572,7 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir,
(void)EC;
if (FS.useNormalizedPaths())
- FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+ llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
if (Path.empty())
return Dir;
OpenPOWER on IntegriCloud