typedef int (*SET_FOLDER_ITEM_VALIDITY)(sqlite3 *, const char *, const char *, int, int, uid_t);
typedef int (*SET_ITEM_VALIDITY)(const char *, const char *, int, int, uid_t);
typedef int (*DELETE_ITEM)(sqlite3 *, const char *, const char *, uid_t);
-typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(sqlite3 *, const char *, int, uid_t);
typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(sqlite3 *, const char *, const char *, bool, uid_t);
typedef int (*UPDATE_FOLDER_TIME)(sqlite3 *, const char *, const char *, uid_t);
typedef int (*GET_STORAGE_ID)(sqlite3 *, const char *, char *, uid_t uid);
int ms_validate_item(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
int ms_insert_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid);
int ms_validity_change_all_items(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, bool validity, uid_t uid);
-bool ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, uid_t uid);
+bool ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, uid_t uid);
int ms_set_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *path, int validity, int recursive, uid_t uid);
int ms_delete_invalid_items_in_folder(sqlite3 *handle, const char *storage_id, const char *path, bool is_recursive, uid_t uid);
int ms_send_dir_update_noti(sqlite3 *handle, const char *storage_id, const char *path, const char *folder_id, ms_noti_type_e noti_type, int pid);
eSET_VALIDITY_BEGIN,
eSET_VALIDITY_END,
eSET_VALIDITY,
- eDELETE_INVALID_ITEMS,
eSET_FOLDER_ITEM_VALIDITY,
eDELETE_FOLDER,
eSEND_DIR_UPDATE_NOTI,
"set_item_validity_begin",
"set_item_validity_end",
"set_item_validity",
- "delete_all_invalid_items_in_storage",
"set_folder_item_validity",
"delete_all_invalid_items_in_folder",
"send_dir_update_noti",
return ret;
}
-bool ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, uid_t uid)
+bool ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, uid_t uid)
{
- int lib_index;
int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ GArray *thumb_list = NULL;
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_INVALID_ITMES_IN_STORAGE)func_array[lib_index][eDELETE_INVALID_ITEMS])(handle, storage_id, storage_type, uid); /*dlopen*/
- MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, false, "Error : %s", g_array_index(so_array, char*, lib_index));
+ MS_DBG_RETVM_IF(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+
+ thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
+
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%q' WHERE validity=0 AND thumbnail_path IS NOT NULL", storage_id);
+
+ MS_DBG_SLOG("[SQL query] : %s", sql);
+
+ ret = media_db_get_result(handle, sql, &sql_stmt);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Query failed. err[%d]", ret);
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ char *path = NULL;
+ path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ g_array_append_val(thumb_list, path);
}
- return true;
+ MS_SQLITE3_FINALIZE(sql_stmt);
+
+ sql = sqlite3_mprintf("DELETE FROM '%q' WHERE validity = 0;", storage_id);
+
+ ret = media_db_request_update_db(sql, uid);
+ MS_SQLITE3_SAFE_FREE(sql);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ while ((thumb_list != NULL) && (thumb_list->len != 0)) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+ MS_SAFE_FREE(thumb_path);
+ }
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
+ return ret;
+ }
+
+ /*Delete thumbnails*/
+ while ((thumb_list != NULL) && (thumb_list->len != 0)) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+
+ if (remove(thumb_path) != 0)
+ MS_DBG_ERR("fail to remove thumbnail file.");
+
+ MS_SAFE_FREE(thumb_path);
+ }
+
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
+
+ return MS_MEDIA_ERR_NONE;
}
int ms_set_folder_item_validity(sqlite3 *handle, const char *storage_id, const char *path, int validity, int recursive, uid_t uid)
return;
}
+
if (scan_type == MS_MSG_STORAGE_ALL) {
/* Delete all data before full scanning */
- if (!ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, uid))
+ if (!ms_delete_invalid_items(handle, scan_data->storage_id, uid))
MS_DBG_ERR("ms_delete_invalid_items fails");
}
if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
/*delete invalid folder first, then delete invalid item, avoid to folder was deleted but item not when unmount*/
ms_delete_invalid_folder(scan_data->storage_id, storage_type, uid);
- ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, uid);
+ ms_delete_invalid_items(handle, scan_data->storage_id, uid);
}
/* send notification */
ms_bacth_commit_disable(TRUE, TRUE, scan_data->uid);
- if (!ms_delete_invalid_items(handle, storage_id, storage_type, scan_data->uid))
+ if (!ms_delete_invalid_items(handle, storage_id, scan_data->uid))
MS_DBG_ERR("deleting invalid items in storage failed");
if (ms_delete_invalid_folder(storage_id, storage_type, scan_data->uid) != MS_MEDIA_ERR_NONE)
ms_bacth_commit_disable(TRUE, valid_status, scan_data->uid);
if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
- if (!ms_delete_invalid_items(handle, storage_id, storage_type, scan_data->uid))
+ if (!ms_delete_invalid_items(handle, storage_id, scan_data->uid))
MS_DBG_ERR("deleting invalid items in storage failed");
if (ms_delete_invalid_folder(storage_id, storage_type, scan_data->uid) != MS_MEDIA_ERR_NONE)