| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/simple/simple_index_file.h" | 5 #include "net/disk_cache/simple/simple_index_file.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 bool SimpleIndexFile::TraverseCacheDirectory( | 29 bool SimpleIndexFile::TraverseCacheDirectory( |
| 30 const base::FilePath& cache_path, | 30 const base::FilePath& cache_path, |
| 31 const EntryFileCallback& entry_file_callback) { | 31 const EntryFileCallback& entry_file_callback) { |
| 32 const ScopedDir dir(opendir(cache_path.value().c_str())); | 32 const ScopedDir dir(opendir(cache_path.value().c_str())); |
| 33 if (!dir) { | 33 if (!dir) { |
| 34 PLOG(ERROR) << "opendir " << cache_path.value(); | 34 PLOG(ERROR) << "opendir " << cache_path.value(); |
| 35 return false; | 35 return false; |
| 36 } | 36 } |
| 37 dirent entry, *result; | 37 // In all implementations of the C library that Chromium can run with, |
| 38 while (readdir_r(dir.get(), &entry, &result) == 0) { | 38 // concurrent calls to readdir that specify different directory streams are |
| 39 if (!result) | 39 // thread-safe. This is the case here, since the directory stream is scoped to |
| 40 return true; // The traversal completed successfully. | 40 // the current function. See https://codereview.chromium.org/2411833004/#msg3 |
| 41 const std::string file_name(result->d_name); | 41 errno = 0; |
| 42 for (dirent* entry = readdir(dir.get()); entry; entry = readdir(dir.get())) { |
| 43 const std::string file_name(entry->d_name); |
| 42 if (file_name == "." || file_name == "..") | 44 if (file_name == "." || file_name == "..") |
| 43 continue; | 45 continue; |
| 44 const base::FilePath file_path = cache_path.Append( | 46 const base::FilePath file_path = cache_path.Append( |
| 45 base::FilePath(file_name)); | 47 base::FilePath(file_name)); |
| 46 entry_file_callback.Run(file_path); | 48 entry_file_callback.Run(file_path); |
| 47 } | 49 } |
| 48 PLOG(ERROR) << "readdir_r " << cache_path.value(); | 50 if (!errno) |
| 51 return true; // The traversal completed successfully. |
| 52 PLOG(ERROR) << "readdir " << cache_path.value(); |
| 49 return false; | 53 return false; |
| 50 } | 54 } |
| 51 | 55 |
| 52 } // namespace disk_cache | 56 } // namespace disk_cache |
| OLD | NEW |