char *dir_path = NULL;
const char *token = "/";
char *folder_uuid = NULL;
- char tmp_folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
- bool folder_search_end = false;
char *internal_path = NULL;
- memset(tmp_folder_uuid, 0, sizeof(tmp_folder_uuid));
- ret = ms_user_get_internal_root_path(uid, &internal_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
+ if (storage_type == MS_USER_STORAGE_INTERNAL) {
+ ret = ms_user_get_internal_root_path(uid, &internal_path);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
- if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0))
next_pos = strlen(internal_path);
- else if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0)
- next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL) + 1;
- else {
- media_svc_error("Invalid Path");
- media_svc_sec_error("Invalid Path [%s], internal_path [%s]", path, internal_path);
SAFE_FREE(internal_path);
- return MS_MEDIA_ERR_INTERNAL;
+ } else {
+ media_svc_retvm_if(!STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL), MS_MEDIA_ERR_INTERNAL, "Failed to get root path");
+ next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL) + 1;
}
- SAFE_FREE(internal_path);
-
- while (!folder_search_end) {
+ do {
next = strstr(path + next_pos, token);
- if (next != NULL) {
+ if (next) {
next_pos = (next - path);
- dir_path = strndup(path, next_pos);
+ dir_path = g_strndup(path, next_pos);
next_pos++;
} else {
- dir_path = strndup(path, strlen(path));
- folder_search_end = true;
- media_svc_sec_debug("End Path[%s]", dir_path);
+ dir_path = g_strdup(path);
}
- ret = _media_svc_get_folder_id_by_path(handle, storage_id, dir_path, tmp_folder_uuid);
+ ret = _media_svc_check_folder_by_path(handle, storage_id, dir_path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ SAFE_FREE(folder_uuid);
folder_uuid = _media_info_generate_uuid();
if (folder_uuid == NULL) {
media_svc_error("Invalid UUID");
- SAFE_FREE(dir_path);
+ g_free(dir_path);
return MS_MEDIA_ERR_INTERNAL;
}
media_svc_sec_debug("Append new folder path[%s] uuid[%s]", dir_path, folder_uuid);
}
- SAFE_FREE(dir_path);
- }
+ g_free(dir_path);
+ } while (next);
if (STRING_VALID(folder_uuid)) {
SAFE_STRLCPY(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE + 1);
int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
char folder_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
- ret = _media_svc_get_folder_id_by_path(handle, storage_id, path, folder_id);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = _media_svc_check_folder_by_path(handle, storage_id, path);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
ret = __media_svc_get_and_append_parent_folder(handle, true, storage_id, path, storage_type, folder_id, uid);
- } else {
- sql = sqlite3_mprintf("UPDATE %q SET validity=1 WHERE storage_uuid = '%q' AND folder_path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path);
- ret = _media_svc_sql_query_direct(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- }
+ else
+ ret = _media_svc_set_folder_validity(true, storage_id, path, 1, false, uid);
return ret;
}
-int _media_svc_set_folder_validity(sqlite3 *handle, bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
+int _media_svc_set_folder_validity(bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
return _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, uid);
}
-int media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
+int media_svc_set_folder_validity(const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
{
- return _media_svc_set_folder_validity(handle, true, storage_id, start_path, validity, is_recursive, uid);
+ return _media_svc_set_folder_validity(true, storage_id, start_path, validity, is_recursive, uid);
}
int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
int _media_svc_update_folder_modified_time_by_folder_uuid(const char *folder_uuid, const char *folder_path, uid_t uid);
int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid);
int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid);
-int _media_svc_set_folder_validity(sqlite3 *handle, bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid);
+int _media_svc_set_folder_validity(bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid);
int _media_svc_check_folder_by_path(sqlite3 *handle, const char *storage_id, const char *path);
#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/