Diff between be9876dd61b8faae3295648a10ec7fcc6174a69c and 0f03ab4f03911fd26d6717b565fa47e33afc1e8f

Changed Files

File Additions Deletions Status
src/adapter.c +1 -13 modified
src/device.c +4 -0 modified
src/shared/util.c +17 -0 modified
src/shared/util.h +2 -0 modified

Full Patch

diff --git a/src/adapter.c b/src/adapter.c
index 602c2fd..60c0261 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2804,18 +2804,6 @@ static uint8_t get_le_addr_type(GKeyFile *keyfile)
 	return addr_type;
 }
 
-static unsigned char dirent_type(const char *parent, const char *name)
-{
-	char filename[PATH_MAX];
-	struct stat st;
-
-	snprintf(filename, sizeof(filename), "%s/%s", parent, name);
-	if (lstat(filename, &st) == 0 && S_ISDIR(st.st_mode))
-		return DT_DIR;
-
-	return DT_UNKNOWN;
-}
-
 static void load_devices(struct btd_adapter *adapter)
 {
 	char dirname[PATH_MAX];
@@ -2848,7 +2836,7 @@ static void load_devices(struct btd_adapter *adapter)
 		uint8_t bdaddr_type;
 
 		if (entry->d_type == DT_UNKNOWN)
-			entry->d_type = dirent_type(dirname, entry->d_name);
+			entry->d_type = util_get_dt(dirname, entry->d_name);
 
 		if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
 			continue;
diff --git a/src/device.c b/src/device.c
index 31d6d0b..3f74b2c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -45,6 +45,7 @@
 
 #include "log.h"
 
+#include "src/shared/util.h"
 #include "btio/btio.h"
 #include "lib/uuid.h"
 #include "lib/mgmt.h"
@@ -2594,6 +2595,9 @@ static void delete_folder_tree(const char *dirname)
 				g_str_equal(entry->d_name, ".."))
 			continue;
 
+		if (entry->d_type == DT_UNKNOWN)
+			entry->d_type = util_get_dt(dirname, entry->d_name);
+
 		snprintf(filename, PATH_MAX, "%s/%s", dirname, entry->d_name);
 
 		if (entry->d_type == DT_DIR)
diff --git a/src/shared/util.c b/src/shared/util.c
index eb90ecb..8530440 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -28,6 +28,10 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
 
 #include "src/shared/util.h"
 
@@ -88,3 +92,16 @@ void util_hexdump(const char dir, const unsigned char *buf, size_t len,
 		function(str, user_data);
 	}
 }
+
+/* Helper for getting the dirent type in case readdir returns DT_UNKNOWN */
+unsigned char util_get_dt(const char *parent, const char *name)
+{
+	char filename[PATH_MAX];
+	struct stat st;
+
+	snprintf(filename, sizeof(filename), "%s/%s", parent, name);
+	if (lstat(filename, &st) == 0 && S_ISDIR(st.st_mode))
+		return DT_DIR;
+
+	return DT_UNKNOWN;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 4bc77a1..04c600f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -91,6 +91,8 @@ void util_debug(util_debug_func_t function, void *user_data,
 void util_hexdump(const char dir, const unsigned char *buf, size_t len,
 				util_debug_func_t function, void *user_data);
 
+unsigned char util_get_dt(const char *parent, const char *name);
+
 static inline void bswap_128(const void *src, void *dst)
 {
 	const uint8_t *s = src;