[Lldb-commits] [lldb] r242753 - Fix FileSpec::IsSymlink implementation.

Oleksiy Vyalov ovyalov at google.com
Mon Jul 20 18:28:23 PDT 2015


Author: ovyalov
Date: Mon Jul 20 20:28:22 2015
New Revision: 242753

URL: http://llvm.org/viewvc/llvm-project?rev=242753&view=rev
Log:
Fix FileSpec::IsSymlink implementation.

http://reviews.llvm.org/D11356



Modified:
    lldb/trunk/include/lldb/Host/FileSpec.h
    lldb/trunk/source/Host/common/FileSpec.cpp

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=242753&r1=242752&r2=242753&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Mon Jul 20 20:28:22 2015
@@ -510,10 +510,7 @@ public:
     }
 
     bool
-    IsSymbolicLink () const
-    {
-        return GetFileType() == FileSpec::eFileTypeSymbolicLink;
-    }
+    IsSymbolicLink () const;
 
     //------------------------------------------------------------------
     /// Get the memory cost of this object.

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=242753&r1=242752&r2=242753&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Mon Jul 20 20:28:22 2015
@@ -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
 {





More information about the lldb-commits mailing list