Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
removed_image_repository.c File Reference
#include "database/removed_image_repository.h"
#include "common/logging.h"
#include "database/database.h"
#include "database/sql_debug.h"
#include "system/macros.h"
#include "system/mem_alloc.h"
#include <sqlite3.h>
+ Include dependency graph for removed_image_repository.c:

Go to the source code of this file.

Data Structures

struct  _removed_table_t
 

Typedefs

typedef struct _removed_table_t _removed_table_t
 

Functions

static gchar * _columns_of (const char *table)
 
static gboolean _run (const char *query, const int snap_id, const int32_t imgid)
 
static int _next_id (const int32_t imgid)
 
static void _debug_memory (const char *stage, const int snap_id, const int32_t imgid)
 
int dt_removed_image_repository_create (const int32_t imgid)
 Copy every row imgid owns out of main, so the removal about to happen can be undone.
 
gboolean dt_removed_image_repository_restore (const int snap_id, const int32_t imgid)
 Copy snapshot snap_id of imgid back into main, film roll included.
 
void dt_removed_image_repository_clear (const int snap_id, const int32_t imgid)
 Drop snapshot snap_id of imgid, making the removal permanent.
 

Variables

static const _removed_table_t _removed_tables []
 

Typedef Documentation

◆ _removed_table_t

Function Documentation

◆ _columns_of()

static gchar * _columns_of ( const char *  table)
static

◆ _debug_memory()

static void _debug_memory ( const char *  stage,
const int  snap_id,
const int32_t  imgid 
)
static

◆ _next_id()

static int _next_id ( const int32_t  imgid)
static

◆ _run()

static gboolean _run ( const char *  query,
const int  snap_id,
const int32_t  imgid 
)
static

◆ dt_removed_image_repository_clear()

void dt_removed_image_repository_clear ( const int  snap_id,
const int32_t  imgid 
)

Drop snapshot snap_id of imgid, making the removal permanent.

Definition at line 264 of file removed_image_repository.c.

References _debug_memory(), _removed_tables, _run(), dt_free, i, and name.

Referenced by _remove_undo_data_free(), and test_clear_drops_the_snapshot().

◆ dt_removed_image_repository_create()

int dt_removed_image_repository_create ( const int32_t  imgid)

Copy every row imgid owns out of main, so the removal about to happen can be undone.

Call this BEFORE anything touches the image: the group membership of the images staying behind is part of the snapshot, and removing a group's leader rewrites it.

The snapshot id is allocated here rather than asked for separately, so that reading the highest id an image already has and writing rows under the next one happen inside the same transaction.

Returns
The snapshot id, to be handed back to restore() and clear(), or -1 when a statement failed. The whole thing is one transaction and rolls back in that case, and the caller must remove the image without an undo record rather than record one that cannot restore anything.

Definition at line 138 of file removed_image_repository.c.

References _columns_of(), _debug_memory(), _next_id(), _removed_tables, _run(), dt_database_release_transaction, dt_database_rollback_transaction(), dt_database_start_transaction, dt_free, i, IS_NULL_PTR, name, and TRUE.

Referenced by _image_remove(), test_clear_drops_the_snapshot(), test_film_roll_comes_back_with_its_last_image(), test_group_leader_restores_membership(), test_partial_undo_repoints_a_departed_leader(), test_round_trip_restores_every_table(), test_successive_snapshots_do_not_collide(), and test_whole_group_removed_and_fully_undone_keeps_one_group().

◆ dt_removed_image_repository_restore()

gboolean dt_removed_image_repository_restore ( const int  snap_id,
const int32_t  imgid 
)

Copy snapshot snap_id of imgid back into main, film roll included.

Foreign keys are deferred to the commit, because an image is restored before the group leader it points at may be: a group removed in one go comes back one image per undo record, in whatever order the undo list holds. Any group_id still dangling at the end of the restore is repointed at the image itself rather than left to fail the commit.

Returns
TRUE when every statement succeeded; the transaction rolls back otherwise.

Definition at line 193 of file removed_image_repository.c.

References _columns_of(), _removed_tables, _run(), dt_database_get_sqlite3_global(), dt_database_release_transaction, dt_database_rollback_transaction(), dt_database_start_transaction, dt_free, i, IS_NULL_PTR, name, and TRUE.

Referenced by _pop_undo(), test_clear_drops_the_snapshot(), test_film_roll_comes_back_with_its_last_image(), test_group_leader_restores_membership(), test_partial_undo_repoints_a_departed_leader(), test_round_trip_restores_every_table(), test_successive_snapshots_do_not_collide(), and test_whole_group_removed_and_fully_undone_keeps_one_group().

Variable Documentation

◆ _removed_tables

const _removed_table_t _removed_tables[]
static
Initial value:
= { { "film_rolls", "id IN (SELECT film_id FROM main.images WHERE id = ?2)", NULL },
{ "images", "id = ?2", NULL },
{ "history", "imgid = ?2", "imgid" },
{ "masks_history", "imgid = ?2", "imgid" },
{ "module_order", "imgid = ?2", "imgid" },
{ "tagged_images", "imgid = ?2", "imgid" },
{ "color_labels", "imgid = ?2", "imgid" },
{ "meta_data", "id = ?2", "id" },
{ "history_hash", "imgid = ?2", "imgid" } }

Definition at line 52 of file removed_image_repository.c.

Referenced by dt_removed_image_repository_clear(), dt_removed_image_repository_create(), and dt_removed_image_repository_restore().