summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2020-03-13 09:59:11 +0900
committerMinje Ahn <minje.ahn@samsung.com>2020-03-13 12:04:03 +0900
commit3834baae423f56fb249d7e76af552ae74bc56d51 (patch)
tree8671489b501948cb11676e986f8ca0404827ed9b /src
parent8a5dd18fcc73a8df0cbc1e4fd39b7e7cb68e5703 (diff)
downloadlibmedia-service-3834baae423f56fb249d7e76af552ae74bc56d51.tar.gz
libmedia-service-3834baae423f56fb249d7e76af552ae74bc56d51.tar.bz2
libmedia-service-3834baae423f56fb249d7e76af552ae74bc56d51.zip
Folder related functions cleanup
Change-Id: Ief056a3f17116ebfff3fd8ada38f55f432676018
Diffstat (limited to 'src')
-rwxr-xr-xsrc/common/media-svc-media-folder.c55
-rw-r--r--src/common/media-svc-util.c11
-rwxr-xr-xsrc/common/media-svc.c16
-rwxr-xr-xsrc/include/common/media-svc-media-folder.h5
4 files changed, 20 insertions, 67 deletions
diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c
index 4330793..3b399ef 100755
--- a/src/common/media-svc-media-folder.c
+++ b/src/common/media-svc-media-folder.c
@@ -27,23 +27,16 @@
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
-int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid)
+int _media_svc_get_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE storage_uuid=%Q AND folder_path=%Q", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name);
+ sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE folder_path=%Q AND storage_uuid=%Q", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("No record");
- else
- media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
-
- return ret;
- }
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step failed [%d]", ret);
SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
@@ -138,7 +131,7 @@ static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, bool is_dir
media_svc_sec_debug("End Path[%s]", dir_path);
}
- ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, dir_path, tmp_folder_uuid, uid);
+ ret = _media_svc_get_folder_id_by_path(handle, storage_id, dir_path, tmp_folder_uuid);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
folder_uuid = _media_info_generate_uuid();
if (folder_uuid == NULL) {
@@ -150,8 +143,8 @@ static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, bool is_dir
ret = __media_svc_append_folder(is_direct, storage_id, storage_type, folder_uuid, dir_path, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("__media_svc_append_folder is failed");
-
- media_svc_sec_debug("Append new folder path[%s] uuid[%s]", dir_path, folder_uuid);
+ else
+ media_svc_sec_debug("Append new folder path[%s] uuid[%s]", dir_path, folder_uuid);
}
SAFE_FREE(dir_path);
@@ -167,17 +160,6 @@ static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, bool is_dir
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_and_append_folder(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 ret = MS_MEDIA_ERR_NONE;
-
- ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, path, folder_id, uid);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_get_and_append_parent_folder(handle, is_direct, storage_id, path, storage_type, folder_id, uid);
-
- return ret;
-}
-
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)
{
char *dir_path = NULL;
@@ -185,7 +167,9 @@ int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct,
dir_path = g_path_get_dirname(path);
- ret = _media_svc_get_and_append_folder(handle, is_direct, storage_id, dir_path, storage_type, folder_id, uid);
+ ret = _media_svc_get_folder_id_by_path(handle, storage_id, dir_path, folder_id);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+ ret = __media_svc_get_and_append_parent_folder(handle, is_direct, storage_id, dir_path, storage_type, folder_id, uid);
SAFE_FREE(dir_path);
@@ -194,28 +178,19 @@ int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct,
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)
{
- char *path_name = NULL;
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
char folder_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
- path_name = strdup(path);
- if (path_name == NULL) {
- media_svc_error("out of memory");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, path_name, folder_id, uid);
+ 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_get_and_append_parent_folder(handle, true, storage_id, path_name, storage_type, folder_id, uid);
+ 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);
}
- SAFE_FREE(path_name);
-
return ret;
}
@@ -242,7 +217,7 @@ int _media_svc_set_folder_validity(sqlite3 *handle, bool is_direct, const char *
return ret;
}
-int _media_svc_count_folder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
+int _media_svc_check_folder_by_path(sqlite3 *handle, const char *storage_id, const char *path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
@@ -251,14 +226,10 @@ int _media_svc_count_folder_with_path(sqlite3 *handle, const char *storage_id, c
media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE (storage_uuid='%q' AND folder_path='%q')", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, path);
-
+ sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q AND storage_uuid=%Q", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- *count = sqlite3_column_int(sql_stmt, 0);
-
SQLITE3_FINALIZE(sql_stmt);
return MS_MEDIA_ERR_NONE;
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
index 2d8719d..dfb5986 100644
--- a/src/common/media-svc-util.c
+++ b/src/common/media-svc-util.c
@@ -714,14 +714,11 @@ int _media_svc_get_thumbnail_path(media_svc_media_type_e media_type, char *thumb
int _media_svc_get_file_time(const char *full_path)
{
- struct stat statbuf;
- int fd = 0;
+ struct stat statbuf = { 0, };
- memset(&statbuf, 0, sizeof(struct stat));
- fd = stat(full_path, &statbuf);
- if (fd == -1) {
- media_svc_sec_error("stat(%s) fails.", full_path);
- return MS_MEDIA_ERR_INTERNAL;
+ if (stat(full_path, &statbuf) == -1) {
+ media_svc_stderror("stat fails.");
+ return 0;
}
return statbuf.st_mtime;
diff --git a/src/common/media-svc.c b/src/common/media-svc.c
index 8f59feb..55fb6ce 100755
--- a/src/common/media-svc.c
+++ b/src/common/media-svc.c
@@ -728,21 +728,7 @@ int media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const
int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
{
- int ret = MS_MEDIA_ERR_NONE;
- int count = -1;
-
- ret = _media_svc_count_folder_with_path(handle, storage_id, folder_path, &count);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- if (count > 0) {
- media_svc_debug("item is exist in database");
- return MS_MEDIA_ERR_NONE;
- } else {
- media_svc_debug("item is not exist in database");
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- return MS_MEDIA_ERR_NONE;
+ return _media_svc_check_folder_by_path(handle, storage_id, folder_path);
}
int media_svc_append_query(const char *query, uid_t uid)
diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h
index 50bc6a6..28007a3 100755
--- a/src/include/common/media-svc-media-folder.h
+++ b/src/include/common/media-svc-media-folder.h
@@ -26,12 +26,11 @@
#include <stdbool.h>
#include <media-util.h>
-int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid);
+int _media_svc_get_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id);
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(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_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_count_folder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count);
+int _media_svc_check_folder_by_path(sqlite3 *handle, const char *storage_id, const char *path);
#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/