void _media_util_trim_path(const char *input_path, char **output_path);
int _media_util_check_ignore_file(const char *path, bool *ignore);
int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
+int _media_content_check_dir(const char *path);
int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace);
int _media_content_replace_path(const char *path, char *replace_path);
int _media_content_rollback_path(const char *path, char *replace_path);
*/
int media_folder_update_to_db(media_folder_h folder) TIZEN_DEPRECATED_API;
+#ifdef _USE_TVPD_MODE
+/**
+ * @brief insert media folder into database by folder path
+ * @since_tizen 4.0
+ *
+ * @param[in] folder path
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE Successful
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int media_folder_insert_to_db(const char *path);
+#endif
+
+
/**
* @}
*/
void _media_util_trim_path(const char *input_path, char **output_path);
int _media_util_check_ignore_file(const char *path, bool *ignore);
int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
+int _media_content_check_dir(const char *path);
int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace);
int _media_content_replace_path(const char *path, char *replace_path);
int _media_content_rollback_path(const char *path, char *replace_path);
}
#endif
-static int __media_content_check_dir(const char *path)
-{
- DIR *dp = NULL;
- char *real = NULL;
- char *origin = NULL;
-#ifndef _USE_TVPD_MODE
- char result_path[MAX_PATH_LEN] = {0, };
-#endif
- dp = opendir(path);
- if (dp == NULL) {
- media_content_sec_error("path [%s]", path);
- media_content_stderror("open dir fail");
-
- if (errno == EACCES || errno == EPERM)
- return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
- else
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- closedir(dp);
-
- /* Check symbolic link directory */
- real = realpath(path, NULL);
- /* Get trimmed path */
- _media_util_trim_path(path, &origin);
-
-#ifdef _USE_TVPD_MODE
- if (g_strcmp0(real, origin) != 0) {
- media_content_error("symbolic link(directory)");
- media_content_sec_debug("path[%s] real[%s]", origin, real);
- SAFE_FREE(real);
- SAFE_FREE(origin);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-#else
- if (g_str_has_prefix(real, MEDIA_SHARE_PATH)) {
- /* If shared dirctory, it should be change path to TZ_USER_SHARE from realpath */
- snprintf(result_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(MEDIA_SHARE_PATH));
- if (g_strcmp0(result_path, origin) != 0) {
- media_content_error("symbolic link(directory)");
- media_content_sec_debug("path[%s] real[%s]", origin, real);
- SAFE_FREE(real);
- SAFE_FREE(origin);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
- } else {
- if (g_strcmp0(real, origin) != 0) {
- media_content_error("symbolic link(directory)");
- media_content_sec_debug("path[%s] real[%s]", origin, real);
- SAFE_FREE(real);
- SAFE_FREE(origin);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
- }
-#endif
-
- SAFE_FREE(real);
- SAFE_FREE(origin);
-
- return MEDIA_CONTENT_ERROR_NONE;
-}
-
int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
memset(storage_id, 0x00, sizeof(storage_id));
- ret = __media_content_check_dir(repl_path);
+ ret = _media_content_check_dir(repl_path);
media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
if (ret == MEDIA_CONTENT_ERROR_NONE) {
ret = _media_util_check_ignore_dir(path, &ignore_dir);
media_content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
- ret = __media_content_check_dir(path);
+ ret = _media_content_check_dir(path);
media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
#include <media_info_private.h>
#include <media_util_private.h>
+#ifdef _USE_TVPD_MODE
+#include <media_content_type_product.h>
+#endif
static char *g_src_path = NULL;
return ret;
}
#ifdef _USE_TVPD_MODE
+int media_folder_insert_to_db(const char *path)
+{
+ char repl_path[MAX_PATH_LEN] = {0, };
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
+ bool ignore_dir = FALSE;
+
+ media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
+ memset(repl_path, 0, sizeof(repl_path));
+ ret = _media_content_replace_path(path, repl_path);
+ media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+
+ ret = _media_util_check_ignore_dir(repl_path, &ignore_dir);
+ media_content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+
+ ret = _media_content_check_dir(repl_path);
+ media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
+ media_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) {
+ media_content_error("media_svc_get_storage_id failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, 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) {
+ media_content_sec_debug("media_svc_check_folder_exist_by_path : no record : %s", repl_path);
+ media_svc_storage_type_e storage_type = 0;
+
+ ret = media_svc_get_storage_type(repl_path, &storage_type, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, 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) {
+ media_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 {
+ media_content_sec_error("media_svc_insert_folder failed : %d (%s)", ret, repl_path);
+ }
+
+ return _content_error_capi(MEDIA_CONTENT_TYPE, 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) {
+ media_content_sec_error("ms_set_folder_scan_status failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+ } else if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_sec_error("media_svc_check_folder_exist_by_path failed : %d (%s)", ret, repl_path);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+
+ return ret;
+}
+
int media_folder_get_scan_status(const char *storage_uuid, char* path, media_folder_scan_status_e *scan_status)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
return MEDIA_CONTENT_ERROR_NONE;
}
+int _media_content_check_dir(const char *path)
+{
+ DIR *dp = NULL;
+ char *real = NULL;
+ char *origin = NULL;
+#ifndef _USE_TVPD_MODE
+ char result_path[MAX_PATH_LEN] = {0, };
+#endif
+ dp = opendir(path);
+ if (dp == NULL) {
+ media_content_sec_error("path [%s]", path);
+ media_content_stderror("open dir fail");
+
+ if (errno == EACCES || errno == EPERM)
+ return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
+ else
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ closedir(dp);
+
+ /* Check symbolic link directory */
+ real = realpath(path, NULL);
+ /* Get trimmed path */
+ _media_util_trim_path(path, &origin);
+
+#ifdef _USE_TVPD_MODE
+ if (g_strcmp0(real, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+#else
+ if (g_str_has_prefix(real, MEDIA_SHARE_PATH)) {
+ /* If shared dirctory, it should be change path to TZ_USER_SHARE from realpath */
+ snprintf(result_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(MEDIA_SHARE_PATH));
+ if (g_strcmp0(result_path, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+ } else {
+ if (g_strcmp0(real, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+ }
+#endif
+
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+
int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace)
{
int ret = MEDIA_CONTENT_ERROR_NONE;