Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2181)

Unified Diff: base/file_util_posix.cc

Issue 197017: posix: don't complain when stat() fails with ENOENT (Closed)
Patch Set: better Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index b02df8e81ab0c2814c4c396b43c8eecc30be1fb8..5bc3306557abfd8162744bcd89b579bb9eb7ae90 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -645,18 +645,22 @@ bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698