aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-06-16 21:35:23 (GMT)
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-06-16 21:35:23 (GMT)
commit72be0e39bbc2acf12f1379af569b98f9a5afc015 (patch)
tree8da6922164c4fdfb166ab660736602eea25bf8a2
parent6fb619a032bfab5049c950e3b1919d31939b0a3c (diff)
downloadbootable_recovery-72be0e39bbc2acf12f1379af569b98f9a5afc015.zip
bootable_recovery-72be0e39bbc2acf12f1379af569b98f9a5afc015.tar.gz
bootable_recovery-72be0e39bbc2acf12f1379af569b98f9a5afc015.tar.bz2
Don't assume that d_type works when browsing directory
For example, exfat always returns DT_UNKNOWN which makes it impossible to determine the file type using d_type. Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
-rw-r--r--recovery.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 0b59d12..eed7d04 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -747,6 +747,8 @@ static char* browse_directory(const char* path, Device* device) {
return NULL;
}
+ char pathbuf[PATH_MAX];
+ struct stat st;
int d_size = 0;
int d_alloc = 10;
char** dirs = (char**)malloc(d_alloc * sizeof(char*));
@@ -758,8 +760,12 @@ static char* browse_directory(const char* path, Device* device) {
struct dirent* de;
while ((de = readdir(d)) != NULL) {
int name_len = strlen(de->d_name);
+ snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
- if (de->d_type == DT_DIR) {
+ if (lstat(pathbuf, &st) != 0) {
+ LOGE("Failed to stat %s\n", pathbuf);
+ break;
+ } else if (S_ISDIR(st.st_mode)) {
// skip "." and ".." entries
if (name_len == 1 && de->d_name[0] == '.') continue;
if (name_len == 2 && de->d_name[0] == '.' &&
@@ -774,7 +780,7 @@ static char* browse_directory(const char* path, Device* device) {
dirs[d_size][name_len] = '/';
dirs[d_size][name_len+1] = '\0';
++d_size;
- } else if (de->d_type == DT_REG &&
+ } else if (S_ISREG(st.st_mode) &&
name_len >= 4 &&
strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) {
if (z_size >= z_alloc) {