You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/03/13 07:23:34 UTC

svn commit: r1455814 - /incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Author: vinodkone
Date: Wed Mar 13 06:23:34 2013
New Revision: 1455814

URL: http://svn.apache.org/r1455814
Log:
Added os::islink and substituted stat() with
lstat() in os.hpp.

Review: https://reviews.apache.org/r/8681

Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp?rev=1455814&r1=1455813&r2=1455814&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp Wed Mar 13 06:23:34 2013
@@ -420,11 +420,22 @@ inline bool isfile(const std::string& pa
 }
 
 
+inline bool islink(const std::string& path)
+{
+  struct stat s;
+
+  if (::lstat(path.c_str(), &s) < 0) {
+    return false;
+  }
+  return S_ISLNK(s.st_mode);
+}
+
+
 inline bool exists(const std::string& path)
 {
   struct stat s;
 
-  if (::stat(path.c_str(), &s) < 0) {
+  if (::lstat(path.c_str(), &s) < 0) {
     return false;
   }
   return true;
@@ -436,7 +447,7 @@ inline Try<long> mtime(const std::string
 {
   struct stat s;
 
-  if (::stat(path.c_str(), &s) < 0) {
+  if (::lstat(path.c_str(), &s) < 0) {
     return ErrnoError("Error invoking stat for '" + path + "'");
   }
 
@@ -707,6 +718,7 @@ inline std::list<std::string> ls(const s
 // searching the given directory. A match is successful if the pattern is a
 // substring of the file name.
 // NOTE: Directory path should not end with '/'.
+// NOTE: Symbolic links are not followed.
 // TODO(vinod): Support regular expressions for pattern.
 // TODO(vinod): Consider using ftw or a non-recursive approach.
 inline Try<std::list<std::string> > find(
@@ -722,7 +734,7 @@ inline Try<std::list<std::string> > find
   foreach (const std::string& entry, ls(directory)) {
     std::string path = path::join(directory, entry);
     // If it's a directory, recurse.
-    if (isdir(path)) {
+    if (isdir(path) && !islink(path)) {
       Try<std::list<std::string> > matches = find(path, pattern);
       if (matches.isError()) {
         return matches;