From 282e181b58cf72b6ca770dc7ca5f91f135444502 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 23 Jan 2014 18:17:42 -0800 Subject: Revert "Move frameworks/base/tools/ to frameworks/tools/" This reverts commit 9f6a119c8aa276432ece4fe2118bd8a3c9b1067e. --- tools/aapt/FileFinder.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 tools/aapt/FileFinder.cpp (limited to 'tools/aapt/FileFinder.cpp') diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp new file mode 100644 index 000000000000..18775c06863f --- /dev/null +++ b/tools/aapt/FileFinder.cpp @@ -0,0 +1,98 @@ +// +// Copyright 2011 The Android Open Source Project +// + +// File Finder implementation. +// Implementation for the functions declared and documented in FileFinder.h + +#include +#include +#include + +#include +#include + +#include "DirectoryWalker.h" +#include "FileFinder.h" + +//#define DEBUG + +using android::String8; + +// 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, + DirectoryWalker* dw) +{ + // Scan the directory pointed to by basePath + // check files and recurse into subdirectories. + if (!dw->openDir(basePath)) { + return false; + } + /* + * Go through all directory entries. Check each file using checkAndAddFile + * and recurse into sub-directories. + */ + struct dirent* entry; + while ((entry = dw->nextEntry()) != NULL) { + String8 entryName(entry->d_name); + if (entry->d_name[0] == '.') // Skip hidden files and directories + continue; + + String8 fullPath = basePath.appendPathCopy(entryName); + // If this entry is a directory we'll recurse into it + 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 (isFile(fullPath.string()) ) { + checkAndAddFile(fullPath,dw->entryStats(),extensions,fileStore); + } + } + + // Clean up + dw->closeDir(); + + return true; +} + +void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, + Vector& extensions, + KeyedVector& fileStore) +{ + // Loop over the extensions, checking for a match + bool done = false; + String8 ext(path.getPathExtension()); + ext.toLower(); + for (size_t i = 0; i < extensions.size() && !done; ++i) { + String8 ext2 = extensions[i].getPathExtension(); + ext2.toLower(); + // Compare the extensions. If a match is found, add to storage. + if (ext == ext2) { + done = true; + fileStore.add(path,stats->st_mtime); + } + } +} + -- cgit v1.2.3-59-g8ed1b