common : remove hard coding path about internal root directory 17/88417/4
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 19 Sep 2016 01:37:54 +0000 (10:37 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Tue, 20 Sep 2016 06:47:36 +0000 (23:47 -0700)
- Instead, we will use Tizen platform configuration

Change-Id: I04d9963d0e4adb94c7ff8d2e647e1af7dbd1d784
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/CMakeLists.txt
src/common/storage-helper.c

index 07ca279..c853a25 100644 (file)
@@ -140,6 +140,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        eventsystem
        storage
        libgum
+       libtzplatform-config
   )
 
 INCLUDE(FindPkgConfig)
index 0c4562c..ec43863 100644 (file)
@@ -30,6 +30,8 @@
 #include "trace.h"
 #include <mntent.h>
 #include <storage.h>
+#include "userinfo-list.h"
+#include <tzplatform_config.h>
 
 #define BUF_MAX        256
 
@@ -73,39 +75,35 @@ static bool get_storage_id(int sid, storage_type_e type, storage_state_e state,
 resourced_ret_c get_storage_root_paths(int type, GSList **paths)
 {
        struct rd_storage target;
-       DIR *dp_root, *dp_user;
-       struct dirent dentry;
-       struct dirent *result;
        char *root_path;
-       char buf[BUF_MAX];
+       GHashTable *user_table = NULL;
+       GHashTableIter iter;
+       gpointer key, value;
+       int *uid;
 
        switch (type) {
        case INTERNAL:
                _D("Start finding internal root path of all users");
-               dp_root = opendir(RD_SYS_HOME);
-               if (!dp_root) {
-                       _E("Fail to open %s", RD_SYS_HOME);
+               if (get_all_users_info(&user_table) != RESOURCED_ERROR_NONE) {
+                       _E("Fail to get user list");
                        return RESOURCED_ERROR_FAIL;
                }
 
-               while (!readdir_r(dp_root, &dentry, &result) && result != NULL) {
-                       if (dentry.d_name[0] == '.')
-                               continue;
-                       if (snprintf(buf, BUF_MAX, "%s/%s/content", RD_SYS_HOME, dentry.d_name) < 0) {
-                               _D("Fail to make root path of %s. This path will not be included", dentry.d_name);
-                               continue;
+               g_hash_table_iter_init(&iter, user_table);
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       uid = (int*)key;
+                       tzplatform_set_user(*uid);
+                       root_path = strdup(tzplatform_getenv(TZ_USER_CONTENT));
+                       tzplatform_reset_user();
+                       if (!root_path)
+                               _E("Fail to get content path of uid %d", *uid);
+
+                       if (!access(root_path, R_OK)) {
+                               _D("Find new root path : %s", root_path);
+                               *paths = g_slist_append(*paths, root_path);
                        }
-                       dp_user = opendir(buf);
-                       if (!dp_user) {
-                               _D("User %s doesn't have content path", dentry.d_name);
-                               continue;
-                       }
-                       closedir(dp_user);
-                       root_path = strdup(buf);
-                       _D("Find new root path : %s", root_path);
-                       *paths = g_slist_append(*paths, root_path);
                }
-               closedir(dp_root);
+               g_hash_table_destroy(user_table);
                break;
        case EXTERNAL:
                _D("Start finding external root path");