add new api: insert folder item into database 62/183162/1 accepted/tizen/4.0/unified/20180703.101208 submit/tizen_4.0/20180703.065605
authoryujie.cheng <yujie.cheng@samsung.com>
Mon, 2 Jul 2018 08:40:13 +0000 (16:40 +0800)
committercheng yujie <yujie.cheng@samsung.com>
Tue, 3 Jul 2018 05:21:53 +0000 (05:21 +0000)
Change-Id: I6e6e302fa4f6618faa5a7f635386f0318694afc0
(cherry picked from commit 08e3640bb83e0dee257508e1dbf077581a09dc5a)

include/media_util_private.h
include_product/media_folder.h
include_product/media_util_private.h
src/media_content.c
src/media_folder.c
src/media_util_private.c

index 5db2d36..c7b131a 100755 (executable)
@@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path);
 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);
index d4d9638..eefd3a5 100755 (executable)
@@ -445,6 +445,23 @@ int media_folder_set_order(media_folder_h folder, int order) TIZEN_DEPRECATED_AP
  */
 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
+
+
 /**
  * @}
  */
index 1b638fd..cc51c27 100755 (executable)
@@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path);
 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);
index 26042fc..cb2a23e 100755 (executable)
@@ -1456,68 +1456,6 @@ void _media_content_scan_cb_v2(media_request_result_s* result, void *user_data)
 }
 #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;
@@ -1533,7 +1471,7 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 
        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) {
@@ -1587,7 +1525,7 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        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);
 
index 7f30650..072a28a 100755 (executable)
@@ -17,6 +17,9 @@
 
 #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;
 
@@ -529,6 +532,67 @@ int media_folder_set_order(media_folder_h folder, int order)
        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;
index 77ca1af..472fb17 100755 (executable)
@@ -286,6 +286,69 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
        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;