[PATCH] D54448: [FileSystem] Add expand_tilde function
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 12 14:50:27 PST 2018
JDevlieghere updated this revision to Diff 173772.
JDevlieghere added a comment.
Remove useless copy-pasted lines from unit test.
https://reviews.llvm.org/D54448
Files:
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/Unix/Path.inc
llvm/lib/Support/Windows/Path.inc
llvm/unittests/Support/Path.cpp
Index: llvm/unittests/Support/Path.cpp
===================================================================
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -528,6 +528,18 @@
ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/test1"));
}
+TEST_F(FileSystemTest, ExpandTilde) {
+ SmallString<64> Expected;
+ SmallString<64> Actual;
+ SmallString<64> HomeDir;
+ bool Result = llvm::sys::path::home_directory(HomeDir);
+ if (Result) {
+ ASSERT_NO_ERROR(fs::expand_tilde(HomeDir, Expected));
+ ASSERT_NO_ERROR(fs::expand_tilde("~", Actual));
+ EXPECT_EQ(Expected, Actual);
+ }
+}
+
#ifdef LLVM_ON_UNIX
TEST_F(FileSystemTest, RealPathNoReadPerm) {
SmallString<64> Expanded;
Index: llvm/lib/Support/Windows/Path.inc
===================================================================
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -1253,6 +1253,17 @@
Path.insert(Path.begin() + 1, HomeDir.begin() + 1, HomeDir.end());
}
+std::error_code expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) {
+ dest.clear();
+ if (path.isTriviallyEmpty())
+ return std::error_code();
+
+ path.toVector(dest);
+ expandTildeExpr(dest);
+
+ return std::error_code();
+}
+
std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest,
bool expand_tilde) {
dest.clear();
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -550,6 +550,18 @@
llvm::sys::path::append(Path, Storage);
}
+
+std::error_code expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) {
+ dest.clear();
+ if (path.isTriviallyEmpty())
+ return std::error_code();
+
+ path.toVector(dest);
+ expandTildeExpr(dest);
+
+ return std::error_code();
+}
+
static file_type typeForMode(mode_t Mode) {
if (S_ISDIR(Mode))
return file_type::directory_file;
Index: llvm/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/include/llvm/Support/FileSystem.h
+++ llvm/include/llvm/Support/FileSystem.h
@@ -349,6 +349,13 @@
std::error_code real_path(const Twine &path, SmallVectorImpl<char> &output,
bool expand_tilde = false);
+/// Expands ~ expressions to the user's home directory.
+///
+/// @param path The path to resolve.
+/// @returns errc::success if the current path has been resolved in output,
+/// otherwise a platform-specific error_code.
+std::error_code expand_tilde(const Twine &path, SmallVectorImpl<char> &output);
+
/// Get the current path.
///
/// @param result Holds the current path on return.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54448.173772.patch
Type: text/x-patch
Size: 2761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181112/f7262694/attachment.bin>
More information about the llvm-commits
mailing list