[Lldb-commits] [PATCH] D11356: Fix FileSpec::IsSymlink implementation.
Oleksiy Vyalov
ovyalov at google.com
Mon Jul 20 09:14:48 PDT 2015
ovyalov created this revision.
ovyalov added reviewers: clayborg, amccarth.
ovyalov added a subscriber: lldb-commits.
stat call returns information about target file in case of symbolic link.
In order to query symlink status we can use lstat on POSIX systems and GetFileAttributes on Windows.
http://reviews.llvm.org/D11356
Files:
include/lldb/Host/FileSpec.h
source/Host/common/FileSpec.cpp
Index: source/Host/common/FileSpec.cpp
===================================================================
--- source/Host/common/FileSpec.cpp
+++ source/Host/common/FileSpec.cpp
@@ -789,6 +789,28 @@
return eFileTypeInvalid;
}
+bool
+FileSpec::IsSymbolicLink () const
+{
+ char resolved_path[PATH_MAX];
+ if (!GetPath (resolved_path, sizeof (resolved_path)))
+ return false;
+
+#ifdef _WIN32
+ auto attrs = ::GetFileAttributes (resolved_path);
+ if (attrs == INVALID_FILE_ATTRIBUTES)
+ return false;
+
+ return (attrs & FILE_ATTRIBUTE_REPARSE_POINT);
+#else
+ struct stat file_stats;
+ if (::lstat (resolved_path, &file_stats) != 0)
+ return false;
+
+ return (file_stats.st_mode & S_IFMT) == S_IFLNK;
+#endif
+}
+
uint32_t
FileSpec::GetPermissions () const
{
Index: include/lldb/Host/FileSpec.h
===================================================================
--- include/lldb/Host/FileSpec.h
+++ include/lldb/Host/FileSpec.h
@@ -510,10 +510,7 @@
}
bool
- IsSymbolicLink () const
- {
- return GetFileType() == FileSpec::eFileTypeSymbolicLink;
- }
+ IsSymbolicLink () const;
//------------------------------------------------------------------
/// Get the memory cost of this object.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11356.30162.patch
Type: text/x-patch
Size: 1286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150720/e5f088fb/attachment.bin>
More information about the lldb-commits
mailing list