| 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> |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/files/file_util.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 | 17 |
| 17 namespace disk_cache { | 18 namespace disk_cache { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 struct DirCloser { | 21 struct DirCloser { |
| 21 void operator()(DIR* dir) { closedir(dir); } | 22 void operator()(DIR* dir) { closedir(dir); } |
| 22 }; | 23 }; |
| 23 | 24 |
| 24 typedef std::unique_ptr<DIR, DirCloser> ScopedDir; | 25 typedef std::unique_ptr<DIR, DirCloser> ScopedDir; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 } | 37 } |
| 37 dirent entry, *result; | 38 dirent entry, *result; |
| 38 while (readdir_r(dir.get(), &entry, &result) == 0) { | 39 while (readdir_r(dir.get(), &entry, &result) == 0) { |
| 39 if (!result) | 40 if (!result) |
| 40 return true; // The traversal completed successfully. | 41 return true; // The traversal completed successfully. |
| 41 const std::string file_name(result->d_name); | 42 const std::string file_name(result->d_name); |
| 42 if (file_name == "." || file_name == "..") | 43 if (file_name == "." || file_name == "..") |
| 43 continue; | 44 continue; |
| 44 const base::FilePath file_path = cache_path.Append( | 45 const base::FilePath file_path = cache_path.Append( |
| 45 base::FilePath(file_name)); | 46 base::FilePath(file_name)); |
| 46 entry_file_callback.Run(file_path); | 47 base::File::Info file_info; |
| 48 if (!base::GetFileInfo(file_path, &file_info)) { |
| 49 LOG(ERROR) << "Could not get file info for " << file_path.value(); |
| 50 continue; |
| 51 } |
| 52 |
| 53 entry_file_callback.Run(file_path, file_info.last_accessed, |
| 54 file_info.last_modified, file_info.size); |
| 47 } | 55 } |
| 48 PLOG(ERROR) << "readdir_r " << cache_path.value(); | 56 PLOG(ERROR) << "readdir_r " << cache_path.value(); |
| 49 return false; | 57 return false; |
| 50 } | 58 } |
| 51 | 59 |
| 52 } // namespace disk_cache | 60 } // namespace disk_cache |
| OLD | NEW |