+ content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
+
+ ret = _media_content_replace_path(path, repl_path);
+ content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+
+ content_retvm_if(_media_util_is_ignorable_dir(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+
+ ret = _media_content_check_dir(repl_path);
+ content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
+ content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
+
+ ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ content_error("media_svc_get_storage_id failed : %d", ret);
+ return _content_error_capi(ret);
+ }
+
+ ret = media_svc_check_folder_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ content_sec_debug("media_svc_check_folder_exist_by_path : no record : %s", repl_path);
+ ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
+
+ ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ content_sec_error("ms_user_get_storage_type failed : %d", ret);
+ return _content_error_capi(ret);
+ }
+
+ ret = media_svc_insert_folder(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
+ content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path);
+ ret = MEDIA_CONTENT_ERROR_NONE;
+ } else {
+ content_sec_error("media_svc_insert_folder failed : %d (%s)", ret, repl_path);
+ }
+
+ return _content_error_capi(ret);
+ }
+
+ ret = media_svc_set_folder_scan_status(storage_id, repl_path, MEDIA_DIR_SCAN_DONE, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ content_sec_error("ms_set_folder_scan_status failed : %d", ret);
+ return _content_error_capi(ret);
+ }
+ } else if (ret != MS_MEDIA_ERR_NONE) {
+ content_sec_error("media_svc_check_folder_exist_by_path failed : %d (%s)", ret, repl_path);
+ return _content_error_capi(ret);