From 8a578bf5d74d77228d48f2e3d8bdfb10e9dd9653 Mon Sep 17 00:00:00 2001 From: Oleksiy Vyalov Date: Tue, 21 Jul 2015 01:28:22 +0000 Subject: [PATCH] Fix FileSpec::IsSymlink implementation. http://reviews.llvm.org/D11356 llvm-svn: 242753 --- lldb/include/lldb/Host/FileSpec.h | 5 +---- lldb/source/Host/common/FileSpec.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Host/FileSpec.h b/lldb/include/lldb/Host/FileSpec.h index d0338d4..dd6da59 100644 --- a/lldb/include/lldb/Host/FileSpec.h +++ b/lldb/include/lldb/Host/FileSpec.h @@ -510,10 +510,7 @@ public: } bool - IsSymbolicLink () const - { - return GetFileType() == FileSpec::eFileTypeSymbolicLink; - } + IsSymbolicLink () const; //------------------------------------------------------------------ /// Get the memory cost of this object. diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index ceb094b..a917a89 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -789,6 +789,28 @@ FileSpec::GetFileType () const 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 { -- 2.7.4