From be96d69e26c0e91bede570a719f587cacd016d96 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Fri, 24 May 2013 16:40:30 +0100 Subject: [PATCH] filebundle: correct possible bug with fb_scandir() on some FSs --- src/filebundle.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/filebundle.c b/src/filebundle.c index ba3190a5..c40f353a 100644 --- a/src/filebundle.c +++ b/src/filebundle.c @@ -306,7 +306,22 @@ int fb_scandir ( const char *path, fb_dirent ***list ) for (i = 0; i < ret; i++) { (*list)[i] = calloc(1, sizeof(fb_dirent)); strcpy((*list)[i]->name, de[i]->d_name); - (*list)[i]->type = de[i]->d_type == DT_DIR ? FB_DIR : FB_FILE; + switch(de[i]->d_type) { + case DT_DIR: + (*list)[i]->type = FB_DIR; + break; + case DT_REG: + (*list)[i]->type = FB_FILE; + break; + default: { + struct stat st; + char buf[512]; + snprintf(buf, sizeof(buf), "%s/%s", dir->d.root, de[i]->d_name); + if (!lstat(buf, &st)) + (*list)[i]->type = S_ISDIR(st.st_mode) ? FB_DIR : FB_FILE; + break; + } + } free(de[i]); } free(de);