summaryrefslogtreecommitdiff
path: root/src/analysis/db/snapshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/snapshot.c')
-rw-r--r--src/analysis/db/snapshot.c99
1 files changed, 37 insertions, 62 deletions
diff --git a/src/analysis/db/snapshot.c b/src/analysis/db/snapshot.c
index 1a92a34..170cab5 100644
--- a/src/analysis/db/snapshot.c
+++ b/src/analysis/db/snapshot.c
@@ -37,7 +37,6 @@
#include "collection.h"
#include "../../common/compression.h"
#include "../../common/extstr.h"
-#include "../../common/io.h"
#include "../../common/sqlite.h"
#include "../../common/xml.h"
#include "../../core/logs.h"
@@ -69,7 +68,7 @@ static snapshot_node_t *create_snapshot_node(const char *, uint64_t, const char
static void destroy_snapshot_node(snapshot_node_t *);
/* Définit le chemin vers une base de données pour un noeud. */
-static bool setup_snapshot_node_db_path(snapshot_node_t *, const char *, const char *);
+static bool setup_snapshot_node_db_path(snapshot_node_t *, const GCdbArchive *);
/* Valide la présence d'une base de données pour chaque noeud. */
static bool check_snapshot_nodes(const snapshot_node_t *);
@@ -102,9 +101,6 @@ struct _GDbSnapshot
{
GObject parent; /* A laisser en premier */
- char *tmpdir; /* Répertoire de travail */
- char *hash; /* Empreinte de binaire */
-
snapshot_node_t *nodes; /* Instantanés présents */
snapshot_node_t *current; /* Instantané courant */
@@ -133,7 +129,7 @@ static void g_db_snapshot_dispose(GDbSnapshot *);
static void g_db_snapshot_finalize(GDbSnapshot *);
/* Prépare un gestionnaire d'instantanés de bases de données. */
-static GDbSnapshot *g_db_snapshot_new(const char *, const char *);
+static GDbSnapshot *g_db_snapshot_new(const GCdbArchive *);
@@ -231,9 +227,8 @@ static void destroy_snapshot_node(snapshot_node_t *node)
/******************************************************************************
* *
-* Paramètres : node = noeud d'instantané à traiter. *
-* tmpdir = répertoire de travail temporaire. *
-* hash = empreinte du binaire à représenter. *
+* Paramètres : node = noeud d'instantané à traiter. *
+* archive = archive concernée par l'instantané. *
* *
* Description : Définit le chemin vers une base de données pour un noeud. *
* *
@@ -243,23 +238,26 @@ static void destroy_snapshot_node(snapshot_node_t *node)
* *
******************************************************************************/
-static bool setup_snapshot_node_db_path(snapshot_node_t *node, const char *tmpdir, const char *hash)
+static bool setup_snapshot_node_db_path(snapshot_node_t *node, const GCdbArchive *archive)
{
bool result; /* Bilan à retourner */
snapshot_id_t *id; /* Identifiant attribué */
+ char *suffix; /* Fin du fichier temporaire */
int ret; /* Bilan d'une génération */
id = get_snapshot_info_id(&node->info);
- ret = asprintf(&node->path, "%s" G_DIR_SEPARATOR_S "%s_%s_db.sql",
- tmpdir, hash, snapshot_id_as_string(id));
-
+ ret = asprintf(&suffix, "%s_db.sql", snapshot_id_as_string(id));
result = (ret > 0);
if (result)
{
- ret = ensure_path_exists(node->path);
- result = (ret != -1);
+ node->path = g_cdb_archive_get_tmp_filename(archive, suffix);
+
+ free(suffix);
+
+ result = (node->path != NULL);
+
}
return result;
@@ -702,9 +700,6 @@ static void g_db_snapshot_class_init(GDbSnapshotClass *klass)
static void g_db_snapshot_init(GDbSnapshot *snap)
{
- snap->tmpdir = NULL;
- snap->hash = NULL;
-
snap->nodes = NULL;
snap->current = NULL;
@@ -746,12 +741,6 @@ static void g_db_snapshot_dispose(GDbSnapshot *snap)
static void g_db_snapshot_finalize(GDbSnapshot *snap)
{
- if (snap->tmpdir != NULL)
- free(snap->tmpdir);
-
- if (snap->hash != NULL)
- free(snap->hash);
-
if (snap->nodes != NULL)
destroy_snapshot_node(snap->nodes);
@@ -765,8 +754,7 @@ static void g_db_snapshot_finalize(GDbSnapshot *snap)
/******************************************************************************
* *
-* Paramètres : tmpdir = répertoire de travail temporaire. *
-* hash = empreinte du binaire à représenter. *
+* Paramètres : archive = archive associée à l'instantané. *
* *
* Description : Prépare un gestionnaire d'instantanés de bases de données. *
* *
@@ -776,28 +764,15 @@ static void g_db_snapshot_finalize(GDbSnapshot *snap)
* *
******************************************************************************/
-static GDbSnapshot *g_db_snapshot_new(const char *tmpdir, const char *hash)
+static GDbSnapshot *g_db_snapshot_new(const GCdbArchive *archive)
{
GDbSnapshot *result; /* Adresse à retourner */
- int ret; /* Bilan d'une génération */
- bool status; /* Bilan de la création */
result = g_object_new(G_TYPE_DB_SNAPSHOT, NULL);
- result->tmpdir = strdup(tmpdir);
- result->hash = strdup(hash);
+ result->current_db = g_cdb_archive_get_tmp_filename(archive, "current_db.sql");
- ret = asprintf(&result->current_db, "%s" G_DIR_SEPARATOR_S "%s_current_db.sql", tmpdir, hash);
-
- status = (ret > 0);
-
- if (status)
- {
- ret = ensure_path_exists(result->current_db);
- status = (ret != -1);
- }
-
- if (!status)
+ if (result->current_db == NULL)
{
g_object_unref(G_OBJECT(result));
result = NULL;
@@ -810,8 +785,7 @@ static GDbSnapshot *g_db_snapshot_new(const char *tmpdir, const char *hash)
/******************************************************************************
* *
-* Paramètres : tmpdir = répertoire de travail temporaire. *
-* hash = empreinte du binaire à représenter. *
+* Paramètres : archive = archive associée à l'instantané. *
* collections = ensemble de modifications par catégories. *
* *
* Description : Prépare un gestionnaire d'instantanés de bases de données. *
@@ -822,7 +796,7 @@ static GDbSnapshot *g_db_snapshot_new(const char *tmpdir, const char *hash)
* *
******************************************************************************/
-GDbSnapshot *g_db_snapshot_new_empty(const char *tmpdir, const char *hash, GList *collections)
+GDbSnapshot *g_db_snapshot_new_empty(const GCdbArchive *archive, GList *collections)
{
GDbSnapshot *result; /* Adresse à retourner */
sqlite3 *db; /* Base de données à manipuler */
@@ -831,12 +805,12 @@ GDbSnapshot *g_db_snapshot_new_empty(const char *tmpdir, const char *hash, GList
GList *iter; /* Boucle de parcours */
GDbCollection *collec; /* Collection visée manipulée */
- result = g_db_snapshot_new(tmpdir, hash);
+ result = g_db_snapshot_new(archive);
if (result == NULL) goto exit;
result->nodes = create_snapshot_node(NULL, 0, NULL, NULL);
- status = setup_snapshot_node_db_path(result->nodes, tmpdir, hash);
+ status = setup_snapshot_node_db_path(result->nodes, archive);
if (!status) goto error;
result->current = result->nodes;
@@ -886,8 +860,7 @@ GDbSnapshot *g_db_snapshot_new_empty(const char *tmpdir, const char *hash, GList
/******************************************************************************
* *
-* Paramètres : tmpdir = répertoire de travail temporaire. *
-* hash = empreinte du binaire à représenter. *
+* Paramètres : archive = archive associée à l'instantané. *
* xdoc = document XML à compléter. *
* context = contexte pour les recherches. *
* *
@@ -899,7 +872,7 @@ GDbSnapshot *g_db_snapshot_new_empty(const char *tmpdir, const char *hash, GList
* *
******************************************************************************/
-GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xmlDocPtr xdoc, xmlXPathContextPtr context)
+GDbSnapshot *g_db_snapshot_new_from_xml(const GCdbArchive *archive, xmlDocPtr xdoc, xmlXPathContextPtr context)
{
GDbSnapshot *result; /* Adresse à retourner */
xmlXPathObjectPtr xobject; /* Cible d'une recherche */
@@ -916,7 +889,7 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
snapshot_node_t *node; /* Instantané nouveau constitué*/
snapshot_id_t node_id; /* Identifiant de noeud courant*/
- result = g_db_snapshot_new(tmpdir, hash);
+ result = g_db_snapshot_new(archive);
if (result == NULL) goto exit;
/* Chargement de l'ensemble des instantanés */
@@ -1042,7 +1015,8 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
/******************************************************************************
* *
* Paramètres : snap = gestionnaire d'instantanés à constituer. *
-* archive = archive en cours de lecture. *
+* ar = archive en cours de lecture. *
+* archive = archive associée à l'instantané. *
* *
* Description : Associe une base de données aux instantanés chargés. *
* *
@@ -1052,7 +1026,7 @@ GDbSnapshot *g_db_snapshot_new_from_xml(const char *tmpdir, const char *hash, xm
* *
******************************************************************************/
-bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
+bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *ar, const GCdbArchive *archive)
{
bool result; /* Bilan à retourner */
struct archive_entry *entry; /* Elément de l'archive */
@@ -1066,9 +1040,9 @@ bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
result = false;
- for (ret = archive_read_next_header(archive, &entry);
+ for (ret = archive_read_next_header(ar, &entry);
ret == ARCHIVE_OK;
- ret = archive_read_next_header(archive, &entry))
+ ret = archive_read_next_header(ar, &entry))
{
path = archive_entry_pathname(entry);
@@ -1077,7 +1051,7 @@ bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
if (strcmp(path, "current.db") == 0)
{
- if (!dump_archive_entry_into_file(archive, entry, snap->current_db))
+ if (!dump_archive_entry_into_file(ar, entry, snap->current_db))
break;
continue;
@@ -1098,10 +1072,10 @@ bool g_db_snapshot_fill(GDbSnapshot *snap, struct archive *archive)
if (node == NULL)
break;
- if (!setup_snapshot_node_db_path(node, snap->tmpdir, snap->hash))
+ if (!setup_snapshot_node_db_path(node, archive))
break;
- if (!dump_archive_entry_into_file(archive, entry, node->path))
+ if (!dump_archive_entry_into_file(ar, entry, node->path))
break;
}
@@ -1482,8 +1456,9 @@ DBError g_db_snapshot_restore(GDbSnapshot *snap, packed_buffer_t *pbuf, bool *re
/******************************************************************************
* *
-* Paramètres : snap = gestionnaire d'instantanés à consulter. *
-* db = base de données courante. *
+* Paramètres : snap = gestionnaire d'instantanés à consulter. *
+* db = base de données courante. *
+* archive = archive associée à l'instantané. *
* *
* Description : Crée un nouvel instantanés dans l'arborescence. *
* *
@@ -1493,7 +1468,7 @@ DBError g_db_snapshot_restore(GDbSnapshot *snap, packed_buffer_t *pbuf, bool *re
* *
******************************************************************************/
-DBError g_db_snapshot_create(GDbSnapshot *snap, sqlite3 *db)
+DBError g_db_snapshot_create(GDbSnapshot *snap, sqlite3 *db, const GCdbArchive *archive)
{
DBError result; /* Conclusion à retourner */
snapshot_node_t *new; /* Nouvel instantané */
@@ -1503,7 +1478,7 @@ DBError g_db_snapshot_create(GDbSnapshot *snap, sqlite3 *db)
new = create_snapshot_node(NULL, 0, NULL, NULL);
- status = setup_snapshot_node_db_path(new, snap->tmpdir, snap->hash);
+ status = setup_snapshot_node_db_path(new, archive);
if (!status)
{
result = DBE_SYS_ERROR;