posix: don't complain when stat() fails with ENOENT

It's not useful to warn the user about broken symlinks when iterating
a directory tree.

Review URL: http://codereview.chromium.org/197017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25392 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 2237f5d79d68d3245f22bedad3f2a757707fdcd3
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index b02df8e..5bc3306 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -645,18 +645,22 @@
   struct dirent* dent;
   while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) {
     DirectoryEntryInfo info;
-    FilePath full_name;
-    int stat_value;
-
     info.filename = FilePath(dent->d_name);
-    full_name = source.Append(dent->d_name);
+
+    FilePath full_name = source.Append(dent->d_name);
+    int ret;
     if (show_links)
-      stat_value = lstat(full_name.value().c_str(), &info.stat);
+      ret = lstat(full_name.value().c_str(), &info.stat);
     else
-      stat_value = stat(full_name.value().c_str(), &info.stat);
-    if (stat_value < 0) {
-      LOG(ERROR) << "Couldn't stat file: " <<
-          source.Append(dent->d_name).value().c_str() << " errno = " << errno;
+      ret = stat(full_name.value().c_str(), &info.stat);
+    if (ret < 0) {
+      // Print the stat() error message unless it was ENOENT and we're
+      // following symlinks.
+      if (!(ret == ENOENT && !show_links)) {
+        LOG(ERROR) << "Couldn't stat "
+                   << source.Append(dent->d_name).value() << ": "
+                   << strerror(errno);
+      }
       memset(&info.stat, 0, sizeof(info.stat));
     }
     entries->push_back(info);