void dt_film_remove_empty() { // remove all empty film rolls from db: gboolean raise_signal = FALSE; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id,folder FROM film_rolls AS B WHERE (SELECT COUNT(A.id) FROM images AS A WHERE A.film_id=B.id)=0", -1, &stmt, NULL); while (sqlite3_step(stmt) == SQLITE_ROW) { sqlite3_stmt *inner_stmt; raise_signal = TRUE; const gint id = sqlite3_column_int(stmt, 0); const gchar *folder = (const gchar *)sqlite3_column_text(stmt, 1); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM film_rolls WHERE id=?1", -1, &inner_stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(inner_stmt, 1, id); sqlite3_step(inner_stmt); sqlite3_finalize(inner_stmt); if (dt_util_is_dir_empty(folder)) rmdir(folder); } sqlite3_finalize(stmt); if(raise_signal) dt_control_signal_raise(darktable.signals , DT_SIGNAL_FILMROLLS_REMOVED); }
void dt_film_remove_empty() { // remove all empty film rolls from db: GList *empty_dirs = NULL; gboolean ask_before_rmdir = dt_conf_get_bool("ask_before_rmdir"); gboolean raise_signal = FALSE; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id,folder FROM main.film_rolls AS B WHERE " "(SELECT COUNT(*) FROM main.images AS A WHERE " "A.film_id=B.id)=0", -1, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { sqlite3_stmt *inner_stmt; raise_signal = TRUE; const gint id = sqlite3_column_int(stmt, 0); const gchar *folder = (const gchar *)sqlite3_column_text(stmt, 1); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.film_rolls WHERE id=?1", -1, &inner_stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(inner_stmt, 1, id); sqlite3_step(inner_stmt); sqlite3_finalize(inner_stmt); if(dt_util_is_dir_empty(folder)) { if(ask_before_rmdir) empty_dirs = g_list_append(empty_dirs, g_strdup(folder)); else rmdir(folder); } } sqlite3_finalize(stmt); if(raise_signal) dt_control_signal_raise(darktable.signals, DT_SIGNAL_FILMROLLS_REMOVED); // dispatch asking for deletion (and subsequent deletion) to the gui thread if(empty_dirs) g_idle_add(ask_and_delete, empty_dirs); }