summaryrefslogtreecommitdiff
path: root/tools/aapt/FileFinder.cpp
diff options
context:
space:
mode:
author Xavier Ducrohet <xav@android.com> 2011-07-20 18:56:52 -0700
committer Android Git Automerger <android-git-automerger@android.com> 2011-07-20 18:56:52 -0700
commit3a8801e0599cfd8f12750d65ee309e20a33e04f6 (patch)
tree07b015062432700566dec6b77e80779fa2d5eddb /tools/aapt/FileFinder.cpp
parentf5a4dd386fcbe200ad9c5d06ecf66d31ba8d4e30 (diff)
parentb3ab070edb17f00a4b2d0f511ca539c885b28b6f (diff)
am b3ab070e: am 3a2d1c23: am ddb8e3b2: am 9bac0a9f: Merge "Fix to compile for windows"
* commit 'b3ab070edb17f00a4b2d0f511ca539c885b28b6f': Fix to compile for windows
Diffstat (limited to 'tools/aapt/FileFinder.cpp')
-rw-r--r--tools/aapt/FileFinder.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp
index a1f64d017bb0..580528d29a82 100644
--- a/tools/aapt/FileFinder.cpp
+++ b/tools/aapt/FileFinder.cpp
@@ -9,8 +9,9 @@
#include <utils/String8.h>
#include <utils/KeyedVector.h>
-
#include <iostream>
+#include <dirent.h>
+#include <sys/stat.h>
#include "DirectoryWalker.h"
#include "FileFinder.h"
@@ -21,6 +22,25 @@ 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<String8>& extensions,
KeyedVector<String8,time_t>& fileStore,
DirectoryWalker* dw)
@@ -45,14 +65,14 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector<String8>& 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);
}
}
@@ -89,4 +109,5 @@ void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats,
#ifdef DEBUG
cout << endl;
#endif //DEBUG
-} \ No newline at end of file
+}
+