{
int ret = MS_MEDIA_ERR_NONE;
char *dir_path = NULL;
- char *leaf_path = NULL;
- char *usr_path = NULL;
+ char *next = NULL;
+ int next_pos = 0;
ret = ms_check_file_path(full_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("invalid path : %s", full_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
- dir_path = g_path_get_dirname(full_path);
- if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
- MS_DBG_ERR("getting directory path is failed : %s", full_path);
- g_free(dir_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && !strncmp(full_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB))) {
+ next_pos = strlen(MEDIA_ROOT_PATH_USB) + 1;
+ } else {
+ ret = ms_user_get_internal_root_path(uid, &dir_path);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_internal_root_path() fail");
- ret = ms_user_get_internal_root_path(uid, &usr_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_user_get_internal_root_path() fail");
+ next_pos = strlen(dir_path);
g_free(dir_path);
- return MS_MEDIA_ERR_INTERNAL;
+ dir_path = NULL;
}
- while (1) {
- if (ms_check_scan_ignore(dir_path, uid) != MS_MEDIA_ERR_NONE) {
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- break;
- }
-
- if (strcmp(dir_path, usr_path) == 0)
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
- break;
+ while ((next = strstr(full_path + next_pos, "/"))) {
+ next_pos = (next - full_path);
+ dir_path = g_strndup(full_path, next_pos);
+ next_pos++;
- leaf_path = strrchr(dir_path, '/');
- if (leaf_path != NULL) {
- int seek_len = leaf_path -dir_path;
- dir_path[seek_len] = '\0';
- } else {
- MS_DBG_ERR("Fail to find leaf path");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ ret = ms_check_scan_ignore(dir_path, uid);
+ g_free(dir_path);
+ if (ret != MS_MEDIA_ERR_NONE)
break;
- }
}
- g_free(dir_path);
- g_free(usr_path);
-
return ret;
}