struct stat st = { 0, };
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "info is NULL");
content_info->path = g_strdup(path);
content_info->file_name = g_path_get_basename(path);
media_svc_stderror("stat failed");
}
- /* refresh is TRUE when file modified. so only modified_time and size are changed*/
- if (refresh) {
- media_svc_debug("refresh");
- return MS_MEDIA_ERR_NONE;
+ if (!refresh) {
+ media_svc_retv_del_if(!storage_id, MS_MEDIA_ERR_INTERNAL, content_info);
+ content_info->storage_uuid = g_strdup(storage_id);
+ content_info->media_uuid = __media_info_generate_uuid();
}
- content_info->storage_uuid = g_strdup(storage_id);
- media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
- content_info->media_uuid = __media_info_generate_uuid();
- media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
ret = __media_svc_get_mime_type(path, mime_type);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
- media_svc_debug("mime [%s]", mime_type);
-
ret = __media_svc_get_media_type(path, mime_type, &media_type);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
content_info->mime_type = g_strdup(mime_type);
media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
- media_svc_sec_debug("path[%s], media_type[%d]", content_info->path, media_type);
+ media_svc_sec_debug("path[%s], media_type[%d] mime[%s]", content_info->path, media_type, content_info->mime_type);
content_info->media_type = media_type;
content_info->media_meta.recorded_date = g_strdup(p);
}
}
+
if (content_info->media_meta.recorded_date == NULL)
content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
if (mmf_error != FILEINFO_ERROR_NONE)
media_svc_error("fail to free tag attr - err(%x)", mmf_error);
}
+
/* All metadata fields must be empty strings until media_video is deleted */
content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
media_svc_retm_if(!content_info, "content info is NULL");
/* Delete media_svc_content_info_s */
- g_free(content_info->media_uuid);
- g_free(content_info->path);
- g_free(content_info->file_name);
- g_free(content_info->mime_type);
- g_free(content_info->thumbnail_path);
- g_free(content_info->storage_uuid);
+ g_clear_pointer(&content_info->media_uuid, g_free);
+ g_clear_pointer(&content_info->path, g_free);
+ g_clear_pointer(&content_info->file_name, g_free);
+ g_clear_pointer(&content_info->mime_type, g_free);
+ g_clear_pointer(&content_info->thumbnail_path, g_free);
+ g_clear_pointer(&content_info->storage_uuid, g_free);
/* Delete media_svc_content_meta_s */
- g_free(content_info->media_meta.title);
- g_free(content_info->media_meta.album);
- g_free(content_info->media_meta.artist);
- g_free(content_info->media_meta.album_artist);
- g_free(content_info->media_meta.genre);
- g_free(content_info->media_meta.year);
- g_free(content_info->media_meta.recorded_date);
- g_free(content_info->media_meta.track_num);
- g_free(content_info->media_meta.datetaken);
+ g_clear_pointer(&content_info->media_meta.title, g_free);
+ g_clear_pointer(&content_info->media_meta.album, g_free);
+ g_clear_pointer(&content_info->media_meta.artist, g_free);
+ g_clear_pointer(&content_info->media_meta.album_artist, g_free);
+ g_clear_pointer(&content_info->media_meta.genre, g_free);
+ g_clear_pointer(&content_info->media_meta.year, g_free);
+ g_clear_pointer(&content_info->media_meta.recorded_date, g_free);
+ g_clear_pointer(&content_info->media_meta.track_num, g_free);
+ g_clear_pointer(&content_info->media_meta.datetaken, g_free);
}
int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
{
int ret = SQLITE_OK;
sqlite3 *db_handle = NULL;
- char *err = NULL;
+ sql_autoptr err = NULL;
ret = sqlite3_open_v2(path, &db_handle, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
media_svc_retvm_if(ret != SQLITE_OK, ret, "sqlite3_open_v2 failed : %d", ret);
ERROR:
media_svc_error("sqlite3_exec failed : %s", err);
- SQLITE3_SAFE_FREE(err);
sqlite3_close_v2(db_handle);
return ret;
static bool __media_svc_is_exist_in_wordbook(sqlite3 *db_handle, const char *path)
{
- int ret = SQLITE_OK;
- char *err = NULL;
- char *query = NULL;
+ sql_autoptr err = NULL;
+ sql_autoptr q = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
- query = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
-
- ret = sqlite3_exec(db_handle, query, NULL, NULL, &err);
- SQLITE3_SAFE_FREE(query);
- if (ret != SQLITE_OK) {
+ if (sqlite3_exec(db_handle, q, NULL, NULL, &err) != SQLITE_OK) {
media_svc_error("Query failed. [%s]", err);
- SQLITE3_SAFE_FREE(err);
return false;
}
- return sqlite3_changes(db_handle) > 0 ? true : false;
+ return (sqlite3_changes(db_handle) > 0);
}
static void __media_svc_insert_to_wordbook(sqlite3 *db_handle, const char *path)
{
void *handle = NULL;
void (*svc_update) (sqlite3 *, const char *);
- char *query = NULL;
-
- query = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
- sqlite3_exec(db_handle, query, NULL, NULL, NULL);
- sqlite3_free(query);
+ sql_autoptr q = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
+ sqlite3_exec(db_handle, q, NULL, NULL, NULL);
handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
if (!handle) {
bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list)
{
- int ret = SQLITE_OK;
sqlite3 *handle = NULL;
sqlite3_stmt *stmt = NULL;
- char *query = NULL;
+ sql_autoptr q = NULL;
media_svc_retvm_if(!list, false, "list is NULL");
media_svc_retvm_if(!keyword, false, "keyword is NULL");
media_svc_retvm_if(!__media_svc_get_wordbook_handle(uid, &handle), false, "Failed to get handle");
- query = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
- ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
- SQLITE3_SAFE_FREE(query);
-
- if (ret != SQLITE_OK) {
- media_svc_error("Query failed[%d]", ret);
+ q = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
+ if (sqlite3_prepare_v2(handle, q, -1, &stmt, NULL) != SQLITE_OK) {
+ media_svc_error("query failed");
sqlite3_close_v2(handle);
return false;
}