2 // Copyright 2011 The Android Open Source Project
6 // This is a collection of useful functions for finding paths and modification
7 // times of files that match an extension pattern in a directory tree.
8 // and finding files in it.
13 #include <utils/Vector.h>
14 #include <utils/KeyedVector.h>
15 #include <utils/String8.h>
17 #include "DirectoryWalker.h"
19 using namespace android
;
21 // Abstraction to allow for dependency injection. See MockFileFinder.h
22 // for the testing implementation.
25 virtual bool findFiles(String8 basePath
, Vector
<String8
>& extensions
,
26 KeyedVector
<String8
,time_t>& fileStore
,
27 DirectoryWalker
* dw
) = 0;
29 virtual ~FileFinder() {};
32 class SystemFileFinder
: public FileFinder
{
35 /* findFiles takes a path, a Vector of extensions, and a destination KeyedVector
36 * and places path/modification date key/values pointing to
37 * all files with matching extensions found into the KeyedVector
39 * path is a valid system path
40 * extensions should include leading "."
41 * This is not necessary, but the comparison directly
42 * compares the end of the path string so if the "."
43 * is excluded there is a small chance you could have
44 * a false positive match. (For example: extension "png"
45 * would match a file called "blahblahpng")
48 * fileStore contains (in no guaranteed order) paths to all
49 * matching files encountered in subdirectories of path
50 * as keys in the KeyedVector. Each key has the modification time
51 * of the file as its value.
53 * Calls checkAndAddFile on each file encountered in the directory tree
54 * Recursively descends into subdirectories.
56 virtual bool findFiles(String8 basePath
, Vector
<String8
>& extensions
,
57 KeyedVector
<String8
,time_t>& fileStore
,
62 * checkAndAddFile looks at a single file path and stat combo
63 * to determine whether it is a matching file (by looking at
70 * If the given file has a matching extension then a new entry
71 * is added to the KeyedVector with the path as the key and the modification
75 static void checkAndAddFile(String8 path
, const struct stat
* stats
,
76 Vector
<String8
>& extensions
,
77 KeyedVector
<String8
,time_t>& fileStore
);
80 #endif // FILEFINDER_H