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

Unified Diff: net/disk_cache/simple/simple_index_file_posix.cc

Issue 2411833004: Replace some deprecated usages of readdir_r with readdir (Closed)
Patch Set: Address review comments by Jorge Lucangeli Obes. Created 4 years, 1 month 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 | « base/files/file_enumerator_posix.cc ('k') | sandbox/linux/services/proc_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_file_posix.cc
diff --git a/net/disk_cache/simple/simple_index_file_posix.cc b/net/disk_cache/simple/simple_index_file_posix.cc
index e0dd3dd126a98801b5711eb892d8ca79bd9b3bfc..4dffbdc78f81cea8056ff922ce9a83a367ceaa2b 100644
--- a/net/disk_cache/simple/simple_index_file_posix.cc
+++ b/net/disk_cache/simple/simple_index_file_posix.cc
@@ -34,18 +34,22 @@ bool SimpleIndexFile::TraverseCacheDirectory(
PLOG(ERROR) << "opendir " << cache_path.value();
return false;
}
- dirent entry, *result;
- while (readdir_r(dir.get(), &entry, &result) == 0) {
- if (!result)
- return true; // The traversal completed successfully.
- const std::string file_name(result->d_name);
+ // In all implementations of the C library that Chromium can run with,
+ // concurrent calls to readdir that specify different directory streams are
+ // thread-safe. This is the case here, since the directory stream is scoped to
+ // the current function. See https://codereview.chromium.org/2411833004/#msg3
+ errno = 0;
+ for (dirent* entry = readdir(dir.get()); entry; entry = readdir(dir.get())) {
+ const std::string file_name(entry->d_name);
if (file_name == "." || file_name == "..")
continue;
const base::FilePath file_path = cache_path.Append(
base::FilePath(file_name));
entry_file_callback.Run(file_path);
}
- PLOG(ERROR) << "readdir_r " << cache_path.value();
+ if (!errno)
+ return true; // The traversal completed successfully.
+ PLOG(ERROR) << "readdir " << cache_path.value();
return false;
}
« no previous file with comments | « base/files/file_enumerator_posix.cc ('k') | sandbox/linux/services/proc_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698