*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*/
#include <glib/gstdio.h>
-#include <media-util-err.h>
+#include <media-util-user.h>
+
#include "media-svc-media-folder.h"
#include "media-svc-debug.h"
#include "media-svc-env.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
-int _media_svc_get_folder_id_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *folder_id)
+static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, long long int *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 folder_path=%Q AND storage_uuid=%Q", DB_TABLE_FOLDER, path, storage_id);
+ sql = sqlite3_mprintf("SELECT folder_id FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
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);
+ *folder_id = sqlite3_column_int64(sql_stmt, 0);
SQLITE3_FINALIZE(sql_stmt);
return ret;
}
-static int __media_svc_append_folder(bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *folder_id, const char *folder_path, uid_t uid)
+static int __media_svc_append_folder(bool is_direct, const char *storage_id, const char *folder_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *folder_name = NULL;
folder_name = g_path_get_basename(folder_path);
folder_modified_date = _media_svc_get_file_time(folder_path);
- /*Update Pinyin If Support Pinyin*/
- char *folder_name_pinyin = NULL;
- if (_media_svc_check_pinyin_support())
- _media_svc_get_pinyin_str(folder_name, &folder_name_pinyin);
/* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
- char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_id, folder_path, folder_name, storage_uuid, folder_storage_type, folder_modified_time, folder_name_pinyin) values (%Q, %Q, %Q, %Q, '%d', '%d', %Q); ",
- DB_TABLE_FOLDER, folder_id, folder_path, folder_name, storage_id, storage_type, folder_modified_date, folder_name_pinyin);
+ char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_path, folder_name, storage_uuid, folder_modified_time) VALUES (%Q, %Q, %Q, '%d');",
+ DB_TABLE_FOLDER, folder_path, folder_name, storage_id, folder_modified_date);
if (is_direct)
ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
g_free(folder_name);
- g_free(folder_name_pinyin);
return ret;
}
-int _media_svc_update_folder_modified_time_by_folder_uuid(const char *folder_uuid, const char *folder_path, uid_t uid)
+int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- int modified_time = 0;
+ int time = 0;
+ char *query = NULL;
- modified_time = _media_svc_get_file_time(folder_path);
+ time = _media_svc_get_file_time(folder_path);
+ query = sqlite3_mprintf("UPDATE %q SET folder_modified_time=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, time, folder_path);
- char *sql = sqlite3_mprintf("UPDATE %q SET folder_modified_time=%d WHERE folder_id=%Q;", DB_TABLE_FOLDER, modified_time, folder_uuid);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
+ ret = _media_svc_sql_query(query, uid);
+ SQLITE3_SAFE_FREE(query);
return ret;
}
-static int __media_svc_get_and_append_parent_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)
+static int __media_svc_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- unsigned int next_pos = 0;
+ size_t next_pos = ms_user_get_root_length(path, uid);
char *next = NULL;
char *dir_path = NULL;
- const char *token = "/";
- char *folder_uuid = NULL;
- char *internal_path = NULL;
-
- if (storage_type == MS_USER_STORAGE_INTERNAL) {
- ret = ms_user_get_internal_root_path(uid, &internal_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
-
- next_pos = strlen(internal_path);
- g_free(internal_path);
- } else {
- media_svc_retvm_if(!STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL), MS_MEDIA_ERR_INTERNAL, "Failed to get root path");
- next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL) + 1;
- }
do {
- next = strstr(path + next_pos, token);
+ next = strstr(path + next_pos, "/");
if (next) {
next_pos = (next - path);
dir_path = g_strndup(path, next_pos);
dir_path = g_strdup(path);
}
- ret = _media_svc_check_folder_by_path(handle, storage_id, dir_path);
+ ret = _media_svc_check_folder_by_path(handle, dir_path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- g_free(folder_uuid);
- folder_uuid = _media_info_generate_uuid();
- if (folder_uuid == NULL) {
- media_svc_error("Invalid UUID");
- g_free(dir_path);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- ret = __media_svc_append_folder(is_direct, storage_id, storage_type, folder_uuid, dir_path, uid);
+ ret = __media_svc_append_folder(is_direct, storage_id, dir_path, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("__media_svc_append_folder is failed");
else
- media_svc_sec_debug("Append new folder path[%s] uuid[%s]", dir_path, folder_uuid);
+ media_svc_sec_debug("Append new folder path[%s]", dir_path);
}
g_free(dir_path);
} while (next);
- if (STRING_VALID(folder_uuid)) {
- SAFE_STRLCPY(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE + 1);
- g_free(folder_uuid);
- } else {
- media_svc_error("Fail to get folder_uuid");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
return MS_MEDIA_ERR_NONE;
}
-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_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, long long int *folder_id, uid_t uid)
{
char *dir_path = NULL;
int ret = MS_MEDIA_ERR_NONE;
dir_path = g_path_get_dirname(path);
- 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);
+ ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = __media_svc_append_parent_folder(handle, is_direct, storage_id, dir_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("__media_svc_append_parent_folder failed");
+ goto FINALIZE;
+ }
+ ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
+ }
+FINALIZE:
g_free(dir_path);
return ret;
}
-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_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char folder_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
- ret = _media_svc_check_folder_by_path(handle, storage_id, path);
+ ret = _media_svc_check_folder_by_path(handle, path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_get_and_append_parent_folder(handle, true, storage_id, path, storage_type, folder_id, uid);
+ ret = __media_svc_append_parent_folder(handle, true, storage_id, path, uid);
else
- ret = _media_svc_set_folder_validity(true, storage_id, path, 1, false, uid);
+ ret = _media_svc_set_folder_validity(true, path, 1, false, uid);
return ret;
}
-int _media_svc_set_folder_validity(bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
+int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
if (is_recursive) {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE storage_uuid='%q' AND (folder_path LIKE '%q/%%' OR folder_path='%q');",
- DB_TABLE_FOLDER, validity, storage_id, start_path, start_path);
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path LIKE '%q/%%' OR folder_path=%Q",
+ DB_TABLE_FOLDER, validity, start_path, start_path);
} else {
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE storage_uuid='%q' AND folder_path='%q';",
- DB_TABLE_FOLDER, validity, storage_id, start_path);
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE folder_path=%Q", DB_TABLE_FOLDER, validity, start_path);
}
if (is_direct)
return ret;
}
-int _media_svc_check_folder_by_path(sqlite3 *handle, const char *storage_id, const char *path)
+int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- 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 1 FROM %q WHERE folder_path=%Q AND storage_uuid=%Q", DB_TABLE_FOLDER, path, storage_id);
+ sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);