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);
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);
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;
+}
/*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.");
+ }
}
}
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_*/