Chromium Code Reviews| Index: base/files/file_enumerator.h |
| diff --git a/base/files/file_enumerator.h b/base/files/file_enumerator.h |
| index 7cac8dd9d457f86366ea54adc1688d36f9121ed9..32ec395aaa63dc17f9dba274721a4cf3d810b893 100644 |
| --- a/base/files/file_enumerator.h |
| +++ b/base/files/file_enumerator.h |
| @@ -84,6 +84,17 @@ class BASE_EXPORT FileEnumerator { |
| #endif |
| }; |
| + // Search policy for intermediate folders. |
| + enum class FolderSearchPolicy { |
| + // Recursive search will pass through folders whose names match the |
| + // pattern. Inside each one, all files will be returned. Folders with names |
| + // that do not match the pattern will be ignored within their interior. |
| + MATCH_ONLY, |
| + // Recursive search will pass through every folder and perform pattern |
| + // matching inside each one. |
| + ALL, |
| + }; |
| + |
| // |root_path| is the starting directory to search for. It may or may not end |
| // in a slash. |
| // |
| @@ -101,9 +112,6 @@ class BASE_EXPORT FileEnumerator { |
| // since the underlying code uses OS-specific matching routines. In general, |
| // Windows matching is less featureful than others, so test there first. |
| // If unspecified, this will match all files. |
| - // NOTE: the pattern only matches the contents of root_path, not files in |
| - // recursive subdirectories. |
| - // TODO(erikkay): Fix the pattern matching to work at all levels. |
| FileEnumerator(const FilePath& root_path, |
| bool recursive, |
| int file_type); |
| @@ -111,6 +119,11 @@ class BASE_EXPORT FileEnumerator { |
| bool recursive, |
| int file_type, |
| const FilePath::StringType& pattern); |
| + FileEnumerator(const FilePath& root_path, |
| + bool recursive, |
| + int file_type, |
| + const FilePath::StringType& pattern, |
| + FolderSearchPolicy folder_search_policy); |
| ~FileEnumerator(); |
| // Returns the next file or an empty string if there are no more results. |
| @@ -127,28 +140,27 @@ class BASE_EXPORT FileEnumerator { |
| // Returns true if the given path should be skipped in enumeration. |
| bool ShouldSkip(const FilePath& path); |
| + bool IsTypeMatched(bool is_dir) const; |
| + |
| + bool IsPatternMatched(const FilePath& src) const; |
| + |
| #if defined(OS_WIN) |
| // True when find_data_ is valid. |
| - bool has_find_data_; |
| + bool has_find_data_ = false; |
| WIN32_FIND_DATA find_data_; |
| - HANDLE find_handle_; |
| + HANDLE find_handle_ = INVALID_HANDLE_VALUE; |
| #elif defined(OS_POSIX) |
| - |
| - // Read the filenames in source into the vector of DirectoryEntryInfo's |
| - static bool ReadDirectory(std::vector<FileInfo>* entries, |
| - const FilePath& source, bool show_links); |
| - |
| // The files in the current directory |
| std::vector<FileInfo> directory_entries_; |
| // The next entry to use from the directory_entries_ vector |
| size_t current_directory_entry_; |
| #endif |
| - |
| FilePath root_path_; |
| bool recursive_; |
| int file_type_; |
| - FilePath::StringType pattern_; // Empty when we want to find everything. |
| + FilePath::StringType pattern_; |
| + FolderSearchPolicy folder_search_policy_; |
|
Lei Zhang
2017/06/08 08:21:17
Make this const? Probably |recursive_| and |file_t
ivafanas
2017/06/16 11:13:15
Done.
|
| // A stack that keeps track of which subdirectories we still need to |
| // enumerate in the breadth-first search. |