*
* 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"
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_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_modified_date = _media_svc_get_file_time(folder_path);
/* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
- char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_path, folder_name, storage_uuid, folder_storage_type, folder_modified_time) VALUES (%Q, %Q, %Q, '%d', '%d');",
- DB_TABLE_FOLDER, folder_path, folder_name, storage_id, storage_type, folder_modified_date);
+ 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);
return ret;
}
-static int __media_svc_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, 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 *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);
ret = _media_svc_check_folder_by_path(handle, dir_path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- ret = __media_svc_append_folder(is_direct, storage_id, storage_type, 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
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, long long int *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;
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, storage_type, uid);
+ 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;
return ret;
}
-int _media_svc_append_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;
ret = _media_svc_check_folder_by_path(handle, path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_append_parent_folder(handle, true, storage_id, path, storage_type, uid);
+ ret = __media_svc_append_parent_folder(handle, true, storage_id, path, uid);
else
ret = _media_svc_set_folder_validity(true, path, 1, false, uid);