OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/disk_cache/simple/simple_index_file.h" | |
6 | |
7 #include <dirent.h> | |
8 #include <sys/stat.h> | |
9 #include <sys/types.h> | |
10 #include <unistd.h> | |
11 | |
12 #include <string> | |
13 | |
14 #include "base/logging.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 | |
17 namespace disk_cache { | |
18 namespace { | |
19 | |
20 struct DirCloser { | |
21 void operator()(DIR* dir) { closedir(dir); } | |
22 }; | |
23 | |
24 typedef scoped_ptr<DIR, DirCloser> ScopedDir; | |
25 | |
26 } // namespace | |
27 | |
28 // static | |
29 bool SimpleIndexFile::TraverseCacheDirectory( | |
30 const base::FilePath& cache_path, | |
31 const EntryFileCallback& entry_file_callback) { | |
32 const ScopedDir dir(opendir(cache_path.value().c_str())); | |
pasko
2013/08/21 16:03:17
this would closedir(NULL) if opendir() failed, is
Philippe
2013/08/21 16:20:58
Yeah, it is :) scoped_ptr<>.reset() only calls the
pasko
2013/08/21 16:29:28
thanks for explanation!
| |
33 if (!dir) { | |
34 PLOG(ERROR) << "opendir " << cache_path.value(); | |
pasko
2013/08/21 16:03:17
I believe you can do:
PLOG(ERROR) << "opendir";
Philippe
2013/08/21 16:20:58
Are you sure perror() prints the filename? To me i
pasko
2013/08/21 16:29:28
you are right, it does not print the dir name for
| |
35 return false; | |
36 } | |
37 dirent entry, *result; | |
38 while (readdir_r(dir.get(), &entry, &result) == 0) { | |
39 if (!result) | |
40 return true; // The traversal completed successfully. | |
41 const std::string file_name(result->d_name); | |
42 if (file_name == "." || file_name == "..") | |
43 continue; | |
44 const base::FilePath file_path = cache_path.Append( | |
45 base::FilePath(file_name)); | |
46 entry_file_callback.Run(file_path); | |
47 } | |
48 PLOG(ERROR) << "readdir_r " << cache_path.value(); | |
49 return false; | |
50 } | |
51 | |
52 } // namespace disk_cache | |
OLD | NEW |