From 241a3ce4c5ff883c160754e0aebd1e1b0894d332 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 4 Sep 2014 12:59:27 -0500 Subject: 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 --- mtp/MtpServer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mtp/MtpServer.cpp') diff --git a/mtp/MtpServer.cpp b/mtp/MtpServer.cpp index 5dec5801e..c044cad7f 100755 --- a/mtp/MtpServer.cpp +++ b/mtp/MtpServer.cpp @@ -1132,7 +1132,12 @@ static void deleteRecursive(const char* path) { 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 { -- cgit v1.2.3