#include <system_info.h>
#endif
+static GMutex tzplatform_mutex;
+
+typedef enum {
+ MEDIA_DB = 0,
+ INTERNAL_ROOT,
+ THUMB_ROOT,
+ THUMB_INTERNAL,
+ THUMB_EXTERNAL
+} ms_user_path_type_e;
+
#ifdef _USE_SENIOR_MODE
bool _ms_is_support_senior_mode()
{
}
#endif
-int ms_user_get_internal_root_path(uid_t uid, char **path)
+static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
{
int ret = MS_MEDIA_ERR_NONE;
+ const char *result = NULL;
+ struct tzplatform_context *context[128];
- if (uid == getuid()) {
- if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
- *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
- } else {
- ret = tzplatform_set_user(uid);
- MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
+ g_mutex_lock(&tzplatform_mutex);
- if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
- *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+ ret = tzplatform_context_create(&context[uid-5000]);
+ if (ret != 0) {
+ MSAPI_DBG_ERR("Fail tzplatform_context_create");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
+ }
+
+ ret = tzplatform_context_set_user(context[uid-5000], uid);
+ if (ret != 0) {
+ MSAPI_DBG_ERR("Fail tzplatform_context_set_user");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
+ }
- tzplatform_reset_user();
+ switch (type) {
+ case MEDIA_DB:
+ result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_DB, ".media.db");
+ break;
+ case INTERNAL_ROOT:
+ result = tzplatform_context_getenv(context[uid-5000], TZ_USER_CONTENT);
+ break;
+ case THUMB_ROOT:
+ result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb");
+ break;
+ case THUMB_INTERNAL:
+ result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/phone");
+ break;
+ case THUMB_EXTERNAL:
+ result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/mmc");
+ break;
+ default:
+ MSAPI_DBG_ERR("Invalid type");
+ ret = MS_MEDIA_ERR_INTERNAL;
+ break;
}
+ *path = g_strdup(result);
+
+ERROR:
+ tzplatform_context_destroy(context[uid-5000]);
+
+ g_mutex_unlock(&tzplatform_mutex);
+
+ return ret;
+}
+
+int ms_user_get_internal_root_path(uid_t uid, char **path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ if (uid == getuid())
+ *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+ else
+ ret = __ms_user_get_path(INTERNAL_ROOT, uid, path);
+
//MSAPI_DBG_SLOG("internal root path [%s]", *path);
return ret;
{
int ret = MS_MEDIA_ERR_NONE;
- if (uid == getuid()) {
- const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
- *path = g_strndup(result, strlen(result));
- } else {
- ret = tzplatform_set_user(uid);
- MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
- const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
- *path = g_strndup(result, strlen(result));
-
- tzplatform_reset_user();
- }
+ if (uid == getuid())
+ *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb"));
+ else
+ ret = __ms_user_get_path(THUMB_ROOT, uid, path);
//MSAPI_DBG_SLOG("thumb path [%s]", *path);
else
*path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc"));
} else {
- ret = tzplatform_set_user(uid);
- MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
if (storage_type == MS_USER_STORAGE_INTERNAL)
- *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/phone"));
+ ret = __ms_user_get_path(THUMB_INTERNAL, uid, path);
else
- *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc"));
-
- tzplatform_reset_user();
+ ret = __ms_user_get_path(THUMB_EXTERNAL, uid, path);
}
//MSAPI_DBG_SLOG("thumb path [%s]", *path);
{
int ret = MS_MEDIA_ERR_NONE;
- if (uid == getuid()) {
- if (MS_STRING_VALID(MEDIA_DB_NAME))
- *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
- } else {
- ret = tzplatform_set_user(uid);
- MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
- if (MS_STRING_VALID(MEDIA_DB_NAME))
- *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
-
- tzplatform_reset_user();
- }
+ if (uid == getuid())
+ *path = g_strdup(tzplatform_mkpath(TZ_USER_DB, ".media.db"));
+ else
+ ret = __ms_user_get_path(MEDIA_DB, uid, path);
//MSAPI_DBG_SLOG("DB path [%s]", *path);