X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/dddb1fc74cc15f34219c2b4eda474245335cdc90..f278f138487e78a7508f79e92cb9413914bbf501:/FileFinder.cpp diff --git a/FileFinder.cpp b/FileFinder.cpp index a1f64d0..18775c0 100644 --- a/FileFinder.cpp +++ b/FileFinder.cpp @@ -9,8 +9,8 @@ #include #include - -#include +#include +#include #include "DirectoryWalker.h" #include "FileFinder.h" @@ -18,8 +18,25 @@ //#define DEBUG using android::String8; -using std::cout; -using std::endl; + +// Private function to check whether a file is a directory or not +bool isDirectory(const char* filename) { + struct stat fileStat; + if (stat(filename, &fileStat) == -1) { + return false; + } + return(S_ISDIR(fileStat.st_mode)); +} + + +// Private function to check whether a file is a regular file or not +bool isFile(const char* filename) { + struct stat fileStat; + if (stat(filename, &fileStat) == -1) { + return false; + } + return(S_ISREG(fileStat.st_mode)); +} bool SystemFileFinder::findFiles(String8 basePath, Vector& extensions, KeyedVector& fileStore, @@ -30,9 +47,6 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector& extensions, if (!dw->openDir(basePath)) { return false; } -#ifdef DEBUG - cout << "FileFinder looking in " << basePath << endl; -#endif // DEBUG /* * Go through all directory entries. Check each file using checkAndAddFile * and recurse into sub-directories. @@ -45,14 +59,14 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector& extensions, String8 fullPath = basePath.appendPathCopy(entryName); // If this entry is a directory we'll recurse into it - if (entry->d_type == DT_DIR) { + if (isDirectory(fullPath.string()) ) { DirectoryWalker* copy = dw->clone(); findFiles(fullPath, extensions, fileStore,copy); delete copy; } // If this entry is a file, we'll pass it over to checkAndAddFile - if (entry->d_type == DT_REG) { + if (isFile(fullPath.string()) ) { checkAndAddFile(fullPath,dw->entryStats(),extensions,fileStore); } } @@ -67,9 +81,6 @@ void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, Vector& extensions, KeyedVector& fileStore) { -#ifdef DEBUG - cout << "Checking file " << path << "..."; -#endif // DEBUG // Loop over the extensions, checking for a match bool done = false; String8 ext(path.getPathExtension()); @@ -79,14 +90,9 @@ void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, ext2.toLower(); // Compare the extensions. If a match is found, add to storage. if (ext == ext2) { -#ifdef DEBUG - cout << "Match"; -#endif // DEBUG done = true; fileStore.add(path,stats->st_mtime); } } -#ifdef DEBUG - cout << endl; -#endif //DEBUG -} \ No newline at end of file +} +