MTP: Better handling of stat
Do some error checking of lstat calls and better handle those
errors.
Use lstat instead of dirent to check if an item is a directory
because dirent does not return the correct item type when using
exfat-fuse.
Change-Id: I0d008aff55a0e0b4fbeae24cf8d0c04453b7b77e
diff --git a/mtp/MtpServer.cpp b/mtp/MtpServer.cpp
index 5dec580..c044cad 100755
--- a/mtp/MtpServer.cpp
+++ b/mtp/MtpServer.cpp
@@ -1132,7 +1132,12 @@
strcpy(fileSpot, name);
int type = entry->d_type;
- if (entry->d_type == DT_DIR) {
+ struct stat st;
+ if (lstat(pathbuf, &st)) {
+ MTPE("Failed to lstat '%s'\n", pathbuf);
+ continue;
+ }
+ if (st.st_mode & S_IFDIR) {
deleteRecursive(pathbuf);
rmdir(pathbuf);
} else {