Fix a bug to remove thumb for music
authorHyunjun Ko <zzoon.ko@samsung.com>
Fri, 12 Apr 2013 09:33:49 +0000 (18:33 +0900)
committerHyunjun Ko <zzoon.ko@samsung.com>
Fri, 12 Apr 2013 09:33:49 +0000 (18:33 +0900)
packaging/libmedia-service.spec
src/common/media-svc-media.c
src/common/media-svc.c
src/include/common/media-svc-media.h

index ebbd31f..ac23514 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmedia-service
 Summary:    Media information service library for multimedia applications.
-Version: 0.2.35
+Version: 0.2.36
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
index a25845c..3559a11 100755 (executable)
@@ -72,7 +72,7 @@ static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media
        int idx = 0;
        sqlite3_stmt *sql_stmt = NULL;
 
-       char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
+       char *sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from %s WHERE storage_type=%d AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0",
                                        MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
 
        media_svc_debug("[SQL query] : %s", sql);
@@ -124,7 +124,7 @@ static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle
        int idx = 0;
        sqlite3_stmt *sql_stmt = NULL;
 
-       char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL",
+       char *sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from %s WHERE path LIKE '%q/%%' AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0",
                                        MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
 
        media_svc_debug("[SQL query] : %s", sql);
@@ -797,4 +797,24 @@ int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_pa
        SQLITE3_FINALIZE(sql_stmt);
 
        return MEDIA_INFO_ERROR_NONE;
-}
\ No newline at end of file
+}
+
+int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *thumb_path, int *count)
+{
+       int ret = MEDIA_INFO_ERROR_NONE;
+       sqlite3_stmt *sql_stmt = NULL;
+       char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE thumbnail_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path);
+
+       ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+       if (ret != MEDIA_INFO_ERROR_NONE) {
+               media_svc_error("error when _media_svc_get_thumbnail_count. err = [%d]", ret);
+               return ret;
+       }
+
+       *count = sqlite3_column_int(sql_stmt, 0);
+
+       SQLITE3_FINALIZE(sql_stmt);
+
+       return MEDIA_INFO_ERROR_NONE;
+}
index ab7e848..90f3325 100755 (executable)
@@ -754,8 +754,19 @@ int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path)
 
        /*Delete thumbnail*/
        if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
-               if (_media_svc_remove_file(thumb_path) == FALSE) {
-                       media_svc_error("fail to remove thumbnail file.");
+               int thumb_count = 1;
+               /* Get count of media, which contains same thumbnail for music */
+               if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+                       ret = _media_svc_get_thumbnail_count(db_handle, thumb_path, &thumb_count);
+                       if (ret < MEDIA_INFO_ERROR_NONE) {
+                               media_svc_error("Failed to get thumbnail count : %d", ret);
+                       }
+               }
+
+               if (thumb_count == 1) {
+                       if (_media_svc_remove_file(thumb_path) == FALSE) {
+                               media_svc_error("fail to remove thumbnail file.");
+                       }
                }
        }
 
index a59ddbc..d7e0ba6 100755 (executable)
@@ -48,5 +48,6 @@ int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *med
 int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path);
 int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item);
 int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_path, int *count);
+int _media_svc_get_thumbnail_count(sqlite3 *handle, const char *thumb_path, int *count);
 
 #endif /*_MEDIA_SVC_MEDIA_H_*/