Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 053ebae

Browse files
committed
[VFS] Add "expand tilde" argument to getRealPath.
Add an optional argument to expand tildes in the path to mirror llvm's implementation of the corresponding function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346453 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8c1c568 commit 053ebae

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

include/llvm/Support/VirtualFileSystem.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ class FileSystem : public llvm::ThreadSafeRefCountedBase<FileSystem> {
274274
/// symlinks. For real file system, this uses `llvm::sys::fs::real_path`.
275275
/// This returns errc::operation_not_permitted if not implemented by subclass.
276276
virtual std::error_code getRealPath(const Twine &Path,
277-
SmallVectorImpl<char> &Output) const;
277+
SmallVectorImpl<char> &Output,
278+
bool ExpandTilde = false) const;
278279

279280
/// Check whether a file exists. Provided for convenience.
280281
bool exists(const Twine &Path);
@@ -330,8 +331,8 @@ class OverlayFileSystem : public FileSystem {
330331
llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
331332
std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
332333
std::error_code isLocal(const Twine &Path, bool &Result) override;
333-
std::error_code getRealPath(const Twine &Path,
334-
SmallVectorImpl<char> &Output) const override;
334+
std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
335+
bool ExpandTilde = false) const override;
335336

336337
using iterator = FileSystemList::reverse_iterator;
337338
using const_iterator = FileSystemList::const_reverse_iterator;
@@ -370,9 +371,9 @@ class ProxyFileSystem : public FileSystem {
370371
std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
371372
return FS->setCurrentWorkingDirectory(Path);
372373
}
373-
std::error_code getRealPath(const Twine &Path,
374-
SmallVectorImpl<char> &Output) const override {
375-
return FS->getRealPath(Path, Output);
374+
std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
375+
bool ExpandTilde = false) const override {
376+
return FS->getRealPath(Path, Output, ExpandTilde);
376377
}
377378

378379
protected:
@@ -465,8 +466,8 @@ class InMemoryFileSystem : public FileSystem {
465466
///
466467
/// This doesn't resolve symlinks as they are not supported in in-memory file
467468
/// system.
468-
std::error_code getRealPath(const Twine &Path,
469-
SmallVectorImpl<char> &Output) const override;
469+
std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
470+
bool ExpandTilde = false) const override;
470471
std::error_code isLocal(const Twine &Path, bool &Result) override;
471472
std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
472473
};

lib/Support/VirtualFileSystem.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {
132132
}
133133

134134
std::error_code FileSystem::getRealPath(const Twine &Path,
135-
SmallVectorImpl<char> &Output) const {
135+
SmallVectorImpl<char> &Output,
136+
bool ExpandTilde) const {
136137
return errc::operation_not_permitted;
137138
}
138139

@@ -238,8 +239,8 @@ class RealFileSystem : public FileSystem {
238239
llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
239240
std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
240241
std::error_code isLocal(const Twine &Path, bool &Result) override;
241-
std::error_code getRealPath(const Twine &Path,
242-
SmallVectorImpl<char> &Output) const override;
242+
std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
243+
bool ExpandTilde = false) const override;
243244

244245
private:
245246
mutable std::mutex CWDMutex;
@@ -297,9 +298,9 @@ std::error_code RealFileSystem::isLocal(const Twine &Path, bool &Result) {
297298
return llvm::sys::fs::is_local(Path, Result);
298299
}
299300

300-
std::error_code
301-
RealFileSystem::getRealPath(const Twine &Path,
302-
SmallVectorImpl<char> &Output) const {
301+
std::error_code RealFileSystem::getRealPath(const Twine &Path,
302+
SmallVectorImpl<char> &Output,
303+
bool ExpandTilde) const {
303304
return llvm::sys::fs::real_path(Path, Output);
304305
}
305306

@@ -393,12 +394,12 @@ std::error_code OverlayFileSystem::isLocal(const Twine &Path, bool &Result) {
393394
return errc::no_such_file_or_directory;
394395
}
395396

396-
std::error_code
397-
OverlayFileSystem::getRealPath(const Twine &Path,
398-
SmallVectorImpl<char> &Output) const {
397+
std::error_code OverlayFileSystem::getRealPath(const Twine &Path,
398+
SmallVectorImpl<char> &Output,
399+
bool ExpandTilde) const {
399400
for (auto &FS : FSList)
400401
if (FS->exists(Path))
401-
return FS->getRealPath(Path, Output);
402+
return FS->getRealPath(Path, Output, ExpandTilde);
402403
return errc::no_such_file_or_directory;
403404
}
404405

@@ -916,9 +917,9 @@ std::error_code InMemoryFileSystem::setCurrentWorkingDirectory(const Twine &P) {
916917
return {};
917918
}
918919

919-
std::error_code
920-
InMemoryFileSystem::getRealPath(const Twine &Path,
921-
SmallVectorImpl<char> &Output) const {
920+
std::error_code InMemoryFileSystem::getRealPath(const Twine &Path,
921+
SmallVectorImpl<char> &Output,
922+
bool ExpandTilde) const {
922923
auto CWD = getCurrentWorkingDirectory();
923924
if (!CWD || CWD->empty())
924925
return errc::operation_not_permitted;

unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class DummyFileSystem : public vfs::FileSystem {
7373
return std::error_code();
7474
}
7575
// Map any symlink to "/symlink".
76-
std::error_code getRealPath(const Twine &Path,
77-
SmallVectorImpl<char> &Output) const override {
76+
std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
77+
bool ExpandTilde) const override {
7878
auto I = FilesAndDirs.find(Path.str());
7979
if (I == FilesAndDirs.end())
8080
return make_error_code(llvm::errc::no_such_file_or_directory);

0 commit comments

Comments
 (0)