![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "system/atomic.h"#include "common/database.h"#include "common/datetime.h"#include "common/file_location.h"#include "common/global_mutexes.h"#include "develop/iop_order.h"#include "common/styles.h"#include "common/history.h"#include "common/legacy_presets.h"#include <gio/gio.h>#include <glib.h>#include <glib/gstdio.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <sys/stat.h>#include <sys/types.h>#include "common/utility.h"#include "widgets/dialog.h"
Include dependency graph for database.c:Go to the source code of this file.
Data Structures | |
| struct | dt_database_t |
Macros | |
| #define | CURRENT_DATABASE_VERSION_LIBRARY 36 |
| #define | CURRENT_DATABASE_VERSION_DATA 9 |
| #define | MAX_NESTED_TRANSACTIONS 0 |
| #define | _SQLITE3_EXEC(a, b, c, d, e) |
| #define | TRY_EXEC(_query, _message) |
| #define | TRY_STEP(_stmt, _expected, _message) |
| #define | TRY_PREPARE(_stmt, _query, _message) |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | TRY_EXEC(_query, _message) |
| #define | TRY_STEP(_stmt, _expected, _message) |
| #define | TRY_PREPARE(_stmt, _query, _message) |
| #define | FINALIZE |
| #define | ERRCHECK {if (err!=NULL) {dt_print(DT_DEBUG_SQL, "[db maintenance] maintenance error: '%s'\n",err); sqlite3_free(err); err=NULL;}} |
Typedefs | |
| typedef struct dt_database_t | dt_database_t |
Variables | |
| static dt_atomic_int | _trxid |
| static dt_atomic_int | _trx_batch_level |
| static gpointer | _trx_owner = NULL |
| static gpointer | _trx_batch_owner = NULL |
| static dt_database_prompt_handler_t | _prompt_handler = NULL |
| #define _SQLITE3_EXEC | ( | a, | |
| b, | |||
| c, | |||
| d, | |||
| e | |||
| ) |
Definition at line 120 of file database.c.
| #define CURRENT_DATABASE_VERSION_DATA 9 |
Definition at line 86 of file database.c.
| #define CURRENT_DATABASE_VERSION_LIBRARY 36 |
Definition at line 85 of file database.c.
| #define ERRCHECK {if (err!=NULL) {dt_print(DT_DEBUG_SQL, "[db maintenance] maintenance error: '%s'\n",err); sqlite3_free(err); err=NULL;}} |
Definition at line 3573 of file database.c.
| #define FINALIZE |
Definition at line 480 of file database.c.
| #define FINALIZE |
Definition at line 480 of file database.c.
| #define FINALIZE |
Definition at line 480 of file database.c.
| #define FINALIZE |
Definition at line 480 of file database.c.
| #define FINALIZE |
Definition at line 480 of file database.c.
| #define MAX_NESTED_TRANSACTIONS 0 |
Definition at line 89 of file database.c.
| #define TRY_EXEC | ( | _query, | |
| _message | |||
| ) |
Definition at line 440 of file database.c.
| #define TRY_EXEC | ( | _query, | |
| _message | |||
| ) |
Definition at line 440 of file database.c.
| #define TRY_PREPARE | ( | _stmt, | |
| _query, | |||
| _message | |||
| ) |
Definition at line 466 of file database.c.
| #define TRY_PREPARE | ( | _stmt, | |
| _query, | |||
| _message | |||
| ) |
Definition at line 466 of file database.c.
| #define TRY_STEP | ( | _stmt, | |
| _expected, | |||
| _message | |||
| ) |
Definition at line 453 of file database.c.
| #define TRY_STEP | ( | _stmt, | |
| _expected, | |||
| _message | |||
| ) |
Definition at line 453 of file database.c.
| typedef struct dt_database_t dt_database_t |
| gboolean _ask_for_maintenance | ( | const gboolean | has_gui, |
| const gboolean | closing_time, | ||
| const guint64 | size | ||
| ) |
Definition at line 3628 of file database.c.
References dt_conf_get_string_const(), dt_free, dt_gui_show_standalone_yes_no_dialog(), FALSE, and size.
Referenced by dt_database_maybe_maintenance().
|
static |
Definition at line 2975 of file database.c.
References _prompt_handler, DT_DATABASE_RESPONSE_CLOSE, and IS_NULL_PTR.
Referenced by dt_database_init().
|
static |
Definition at line 3768 of file database.c.
References _get_pragma_int_val(), DT_DEBUG_SQL, dt_free, dt_print(), MAX, MIN, and void().
Referenced by dt_database_snapshot().
|
static |
Definition at line 2462 of file database.c.
References CURRENT_DATABASE_VERSION_DATA, and dt_database_t::handle.
Referenced by dt_database_init().
|
static |
Definition at line 2356 of file database.c.
References CURRENT_DATABASE_VERSION_LIBRARY, and dt_database_t::handle.
Referenced by dt_database_init().
|
static |
Definition at line 2515 of file database.c.
References dt_database_t::handle.
Referenced by dt_database_init().
|
static |
Definition at line 3531 of file database.c.
References dt_concat_path_file(), dt_loc_get_user_cache_dir(), and PATH_MAX.
Referenced by dt_database_init().
|
static |
Definition at line 3502 of file database.c.
References dt_concat_path_file(), dt_conf_get_string(), dt_conf_set_string(), dt_free, dt_loc_get_datadir(), and PATH_MAX.
Referenced by dt_database_init().
|
static |
Definition at line 4023 of file database.c.
References _get_iso8601_int(), day, and IS_NULL_PTR.
Referenced by dt_database_snaps_to_remove().
|
static |
Definition at line 4003 of file database.c.
References FALSE, i, TRUE, v, and value.
Referenced by _db_snap_sort().
| int _get_pragma_int_val | ( | sqlite3 * | db, |
| const char * | pragma | ||
| ) |
Definition at line 2926 of file database.c.
References dt_free.
Referenced by _backup_db(), dt_database_maybe_maintenance(), and dt_database_perform_maintenance().
| gchar * _get_pragma_string_val | ( | sqlite3 * | db, |
| const char * | pragma | ||
| ) |
|
inlinestatic |
Definition at line 3670 of file database.c.
References dt_database_t::dbfilename_data, and dt_database_t::dbfilename_library.
Referenced by dt_database_maybe_maintenance(), dt_database_maybe_snapshot(), dt_database_optimize(), dt_database_snaps_to_remove(), and dt_database_snapshot().
|
static |
Definition at line 2837 of file database.c.
References _lock_single_database(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, FALSE, dt_database_t::lockfile_data, dt_database_t::lockfile_library, and TRUE.
Referenced by dt_database_init().
|
static |
Definition at line 2744 of file database.c.
References dt_free, dt_database_t::error_dbfilename, dt_database_t::error_message, dt_database_t::error_other_pid, FALSE, pid_is_alive(), and TRUE.
Referenced by _lock_databases().
|
static |
Definition at line 129 of file database.c.
References _SQLITE3_EXEC, dt_free, FALSE, dt_database_t::handle, i, IS_NULL_PTR, name, and TRUE.
Referenced by dt_database_init().
|
static |
Definition at line 3762 of file database.c.
References DT_DEBUG_SQL, and dt_print().
Referenced by dt_database_snapshot().
|
static |
Definition at line 2559 of file database.c.
References dt_free, dt_util_foo_to_utf8(), and dt_database_t::handle.
Referenced by dt_database_init().
|
static |
Definition at line 2342 of file database.c.
References _upgrade_data_schema_step(), CURRENT_DATABASE_VERSION_DATA, FALSE, and TRUE.
Referenced by dt_database_init().
|
static |
Definition at line 2108 of file database.c.
References CURRENT_DATABASE_VERSION_DATA, dt_free_gpointer(), DT_IOP_ORDER_LEGACY, dt_ioppr_get_iop_order_list_version(), dt_database_t::handle, dt_iop_order_entry_t::iop_order_f, dt_iop_order_entry_t::o, dt_iop_order_entry_t::operation, TRY_EXEC, TRY_PREPARE, and TRY_STEP.
Referenced by _upgrade_data_schema().
|
static |
Definition at line 2327 of file database.c.
References _upgrade_library_schema_step(), CURRENT_DATABASE_VERSION_LIBRARY, FALSE, and TRUE.
Referenced by dt_database_init().
|
static |
Definition at line 483 of file database.c.
References CURRENT_DATABASE_VERSION_LIBRARY, dt_datetime_exif_to_gdatetime(), dt_datetime_gdatetime_to_gtimespan(), dt_datetime_utc_tz(), dt_free, dt_free_gpointer(), DT_IMAGE_HDR, DT_IMAGE_LDR, DT_IMAGE_RAW, dt_imageio_get_type_from_extension(), DT_IOP_ORDER_ANSEL_RAW, DT_IOP_ORDER_CUSTOM, DT_IOP_ORDER_LEGACY, dt_ioppr_get_iop_order_list_kind(), dt_ioppr_get_iop_order_list_version(), dt_ioppr_serialize_text_iop_order_list(), dt_sort_iop_list_by_order_f(), FALSE, FINALIZE, flags, dt_database_t::handle, i, dt_iop_order_entry_t::instance, dt_iop_order_entry_t::iop_order_f, IS_NULL_PTR, kind, n, name, dt_iop_order_entry_t::o, dt_iop_order_entry_t::operation, TRUE, TRY_EXEC, TRY_PREPARE, TRY_STEP, and UNKNOWN_IMAGE.
Referenced by _upgrade_library_schema().
| void ask_for_upgrade | ( | const gchar * | dbname, |
| const gboolean | has_gui | ||
| ) |
Definition at line 2850 of file database.c.
References dt_free, and dt_gui_show_standalone_yes_no_dialog().
Referenced by dt_database_init().
| void dt_database_backup | ( | const char * | filename | ) |
Definition at line 2882 of file database.c.
References darktable_package_version, dt_free, FALSE, k, and TRUE.
Referenced by dt_database_init().
| void dt_database_begin_transaction_batch | ( | const struct dt_database_t * | db | ) |
Definition at line 4590 of file database.c.
References _trx_batch_level, _trx_batch_owner, _trx_owner, dt_atomic_add_int(), dt_database_get(), dt_database_threadsafe_lock(), DT_DEBUG_SQLITE3_EXEC, and dt_pthread_rwlock_wrlock().
Referenced by dt_iop_load_modules_so().
| void dt_database_cleanup_busy_statements | ( | const struct dt_database_t * | db | ) |
cleanup busy statements on closing dt, just before performing maintenance
Definition at line 3555 of file database.c.
References DT_DEBUG_SQL, dt_print(), and dt_database_t::handle.
Referenced by dt_cleanup().
| int dt_database_delete_lock_files | ( | const char * | dbfilename | ) |
Delete data.db.lock and library.db.lock beside dbfilename. Returns 0 when every lock file that existed was removed. Call only once the user has agreed.
Definition at line 2673 of file database.c.
References dt_free, i, and IS_NULL_PTR.
Referenced by dt_database_show_error().
| void dt_database_destroy | ( | const dt_database_t * | db | ) |
Definition at line 3472 of file database.c.
References dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_free, dt_database_t::handle, dt_database_t::lockfile_data, and dt_database_t::lockfile_library.
Referenced by dt_cleanup(), and dt_database_init().
| void dt_database_end_transaction_batch | ( | const struct dt_database_t * | db | ) |
Definition at line 4610 of file database.c.
References _trx_batch_level, _trx_batch_owner, _trx_owner, dt_atomic_set_int(), dt_atomic_sub_int(), dt_database_get(), dt_database_threadsafe_lock(), DT_DEBUG_SQL, DT_DEBUG_SQLITE3_EXEC, dt_print(), and dt_pthread_rwlock_unlock().
Referenced by dt_iop_load_modules_so().
| void dt_database_error_free | ( | dt_database_error_t * | error | ) |
Release the strings owned by error.
Definition at line 2664 of file database.c.
References dt_free, error(), and IS_NULL_PTR.
Referenced by dt_database_show_error().
| sqlite3 * dt_database_get | ( | const dt_database_t * | db | ) |
Definition at line 3492 of file database.c.
References dt_database_t::handle.
Referenced by dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_get_sqlite3_global(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), dt_database_start_transaction_debug(), dt_legacy_presets_create(), imported_style_name(), max_style_id(), print_enabled_state_summary(), print_module_order_summary(), and sql_int_for_bound_images().
| gboolean dt_database_get_lock_acquired | ( | const dt_database_t * | db | ) |
Definition at line 3550 of file database.c.
References dt_database_t::lock_acquired.
Referenced by dt_init().
| gchar * dt_database_get_most_recent_snap | ( | const char * | db_filename | ) |
get possibly the freshest snapshot to restore
Definition at line 4361 of file database.c.
References DT_DEBUG_SQL, dt_free, dt_print(), error(), and IS_NULL_PTR.
Referenced by dt_database_init().
| const gchar * dt_database_get_path | ( | const struct dt_database_t * | db | ) |
Returns database path
Definition at line 3497 of file database.c.
References dt_database_t::dbfilename_library.
Referenced by dt_mipmap_cache_get_filename().
| dt_database_t * dt_database_init | ( | const char * | alternative, |
| const gboolean | load_data, | ||
| const gboolean | has_gui | ||
| ) |
allocates and initializes database
Definition at line 2987 of file database.c.
References _ask_user(), _create_data_schema(), _create_library_schema(), _create_memory_schema(), _database_delete_mipmaps_files(), _database_migrate_to_xdg_structure(), _get_pragma_string_val(), _lock_databases(), _migrate_schema(), _sanitize_db(), _trx_batch_level, _trx_batch_owner, _trxid, _upgrade_data_schema(), _upgrade_library_schema(), ask_for_upgrade(), CURRENT_DATABASE_VERSION_DATA, CURRENT_DATABASE_VERSION_LIBRARY, dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_atomic_set_int(), dt_concat_path_file(), dt_conf_get_string(), dt_database_backup(), dt_database_destroy(), dt_database_get_most_recent_snap(), DT_DATABASE_PROMPT_CORRUPTED, DT_DATABASE_PROMPT_READONLY, DT_DATABASE_RESPONSE_DELETE, DT_DATABASE_RESPONSE_RESTORE, DT_DEBUG_SQL, dt_free, dt_legacy_presets_create(), dt_loc_get_datadir(), dt_loc_get_user_config_dir(), dt_print(), error(), FALSE, dt_database_t::handle, IS_NULL_PTR, dt_database_t::lock_acquired, dt_database_t::lockfile_data, dt_database_t::lockfile_library, PATH_MAX, sqlite3IcuInit(), and TRUE.
Referenced by dt_init().
| gboolean dt_database_maybe_maintenance | ( | const struct dt_database_t * | db, |
| const gboolean | has_gui, | ||
| const gboolean | closing_time | ||
| ) |
conditionally perfrom db maintenance
Definition at line 3675 of file database.c.
References _ask_for_maintenance(), _get_pragma_int_val(), _is_mem_db(), dt_conf_get_int(), dt_conf_get_string_const(), DT_DEBUG_SQL, dt_print(), FALSE, dt_database_t::handle, and TRUE.
Referenced by dt_cleanup(), and dt_init().
| gboolean dt_database_maybe_snapshot | ( | const struct dt_database_t * | db | ) |
check if creating database snapshot is recommended
Definition at line 3868 of file database.c.
References _is_mem_db(), dt_database_t::dbfilename_library, dt_conf_get_string_const(), DT_DEBUG_SQL, dt_free, dt_print(), error(), FALSE, IS_NULL_PTR, and TRUE.
Referenced by dt_cleanup().
| void dt_database_optimize | ( | const struct dt_database_t * | db | ) |
perform pre-db-close optimizations (always call when quiting darktable)
Definition at line 3752 of file database.c.
References _is_mem_db(), DT_DEBUG_SQLITE3_EXEC, and dt_database_t::handle.
Referenced by dt_cleanup().
| void dt_database_perform_maintenance | ( | const struct dt_database_t * | db | ) |
Definition at line 3574 of file database.c.
References _get_pragma_int_val(), DT_DEBUG_SQL, DT_DEBUG_SQLITE3_EXEC, dt_print(), ERRCHECK, and dt_database_t::handle.
Referenced by dt_cleanup(), dt_init(), and optimize_database_callback().
| void dt_database_release_transaction_debug | ( | const struct dt_database_t * | db | ) |
Definition at line 4517 of file database.c.
References _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_get_int(), dt_atomic_sub_int(), dt_database_get(), dt_database_threadsafe_lock(), DT_DEBUG_SQLITE3_EXEC, and dt_pthread_rwlock_unlock().
| void dt_database_rollback_transaction | ( | const struct dt_database_t * | db | ) |
Definition at line 4557 of file database.c.
References _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_set_int(), dt_atomic_sub_int(), dt_database_get(), dt_database_threadsafe_lock(), DT_DEBUG_SQLITE3_EXEC, and dt_pthread_rwlock_unlock().
Referenced by _history_snapshot_undo_restore(), dt_exif_xmp_read(), and dt_history_snapshot_undo_create().
| void dt_database_set_prompt_handler | ( | dt_database_prompt_handler_t | handler | ) |
Install the handler dt_database_init() asks through. NULL removes it.
Must be registered BEFORE dt_database_init() runs – which is before dt_gui_gtk_init(), so this one cannot go where the film/collection/folder-survey handlers go. darktable.c registers it, being the only thing that knows this early whether there will be a GUI.
With no handler, every prompt answers CLOSE: a corrupt database is not deleted or restored on the strength of a question nobody was asked. That is also what makes a headless run safe – these dialogs used to be built unconditionally, with no has_gui guard, on a GTK that ansel-cli never initialises.
Definition at line 2968 of file database.c.
References _prompt_handler.
Referenced by dt_database_gui_register_handlers().
| char ** dt_database_snaps_to_remove | ( | const struct dt_database_t * | db | ) |
get list of snapshot files to remove after successful snapshot
Definition at line 4076 of file database.c.
References _db_snap_sort(), _is_mem_db(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_conf_get_int(), DT_DEBUG_SQL, dt_free, dt_print(), error(), FALSE, and IS_NULL_PTR.
Referenced by dt_cleanup().
| gboolean dt_database_snapshot | ( | const struct dt_database_t * | db | ) |
simply create db snapshot of both library and data
Definition at line 3818 of file database.c.
References _backup_db(), _is_mem_db(), _print_backup_progress(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_free, FALSE, dt_database_t::handle, and TRUE.
Referenced by backup_database_callback(), and dt_cleanup().
| void dt_database_start_transaction_debug | ( | const struct dt_database_t * | db | ) |
Definition at line 4467 of file database.c.
References _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_add_int(), dt_atomic_get_int(), dt_database_get(), dt_database_threadsafe_lock(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_wrlock(), and MAX_NESTED_TRANSACTIONS.
| void dt_database_take_error | ( | struct dt_database_t * | db, |
| dt_database_error_t * | error | ||
| ) |
Move the pending error out of db into error, clearing it on the database. Consumes it: a second call reports no error.
Definition at line 2649 of file database.c.
References error(), dt_database_t::error_dbfilename, dt_database_t::error_message, dt_database_t::error_other_pid, IS_NULL_PTR, and dt_database_t::lock_acquired.
Referenced by dt_database_show_error().
|
static |
Definition at line 2697 of file database.c.
References dt_free, FALSE, pid_is_alive(), and TRUE.
Referenced by _lock_single_database(), and pid_is_alive().
|
static |
Definition at line 2966 of file database.c.
Referenced by _ask_user(), and dt_database_set_prompt_handler().
|
static |
Definition at line 92 of file database.c.
Referenced by dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_init(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 94 of file database.c.
Referenced by dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_init(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 93 of file database.c.
Referenced by dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 91 of file database.c.
Referenced by dt_database_init(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().