[PATCH] D30668: Add llvm::sys::fs::real_path
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 6 15:18:56 PST 2017
zturner created this revision.
LLVM currently has a mechanism for resolving symlinks and collapsing . and .. items through the `openFileForRead` method, but it has a couple of limitations:
1. It's not convenient to call, since it requires calling an intermediate function first and interpreting the results, then cleaning up after the function (by closing the file descriptor). It would be nice to just be able to say `real_path(Path, Real);`
2. It requires an open file descriptor, which means that particularly on Windows, there's currently no way to get the real path of a directory ("opening" a directory and opening a file require different code, and we don't expose a method to do the former)
3. On non-Windows platforms, we can't currently handle tilde expressions.
This patch addresses all of this by providing a simple method with the signature `std::error_code real_path(const Twine &, SmallVectorImpl<char> &)`. It works even with directories on Windows, and on Posix platforms it is smart enough to translate `~` into the appropriate home directory.
As a result, `real_path(X)` works like you would expect it to from a bash shell on Linux/Mac/etc, and `real_path(X)` works with directories on Windows, providing maximum portability.
https://reviews.llvm.org/D30668
Files:
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/Unix/Path.inc
llvm/lib/Support/Windows/Path.inc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30668.90751.patch
Type: text/x-patch
Size: 6350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170306/791091f4/attachment.bin>
More information about the llvm-commits
mailing list