#include "trace.h"
#include <mntent.h>
#include <storage.h>
+#include "userinfo-list.h"
+#include <tzplatform_config.h>
#define BUF_MAX 256
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");