DA: Remove all files in connman profile directory 54/283654/1
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 1 Nov 2022 03:37:54 +0000 (12:37 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Tue, 1 Nov 2022 03:37:54 +0000 (12:37 +0900)
Connman profile cannot be deleted by deleting only data and settings files.

Change-Id: Icf8c2d2814e88f2264ebe883bb67ba522456ad72
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
src/wifi-config.c

index 6fa174c..def50d7 100755 (executable)
@@ -288,16 +288,37 @@ static gboolean __remove_file(const gchar *pathname, const gchar *filename)
        return ret;
 }
 
+static gboolean __remove_all_files(const gchar *pathname)
+{
+       DIR *dir_ptr = NULL;
+       struct dirent *file = NULL;
+
+       if ((dir_ptr = opendir(pathname)) == NULL)
+               return TRUE;
+
+       while ((file = readdir(dir_ptr)) != NULL) {
+               if (strncmp(file->d_name, ".", 1) == 0 || strncmp(file->d_name, "..", 2) == 0)
+                       continue;
+
+               if (__remove_file(pathname, file->d_name) != TRUE) {
+                       ERR("Cannot remove [%s/%s]", pathname, file->d_name);
+                       closedir(dir_ptr);
+
+                       return FALSE;
+               }
+       }
+
+       closedir(dir_ptr);
+
+       return TRUE;
+}
+
 static gboolean __remove_configuration(const gchar *pathname)
 {
        int ret = 0;
 
-       if (__remove_file(pathname, "settings") != TRUE) {
-               ERR("Cannot remove [%s/settings]", pathname);
-               return FALSE;
-       }
-       if (__remove_file(pathname, "data") != TRUE) {
-               ERR("Cannot remove [%s/data]", pathname);
+       if (__remove_all_files(pathname) != TRUE) {
+               ERR("Cannot remove [%s] directory", pathname);
                return FALSE;
        }