summaryrefslogtreecommitdiff
path: root/src/analysis/db/cdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/cdb.c')
-rw-r--r--src/analysis/db/cdb.c63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c
index e4179d3..62de6a7 100644
--- a/src/analysis/db/cdb.c
+++ b/src/analysis/db/cdb.c
@@ -366,11 +366,8 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
if (!mkpath(tmpdir))
goto error;
- ret = asprintf(&result->xml_desc, "%s" G_DIR_SEPARATOR_S "%s_desc.xml", tmpdir, get_rle_string(hash));
- if (ret == -1) goto no_tmp;
-
- ret = ensure_path_exists(result->xml_desc);
- if (ret == -1) goto no_tmp;
+ result->xml_desc = g_cdb_archive_get_tmp_filename(result, "desc.xml");
+ if (result->xml_desc == NULL) goto no_tmp;
/* Création de l'archive si elle n'existe pas */
@@ -381,7 +378,7 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
/* Le soucis ne vient pas de l'absence du fichier... */
if (errno != ENOENT) goto error;
- result->snapshot = g_db_snapshot_new_empty(tmpdir, get_rle_string(hash), result->collections);
+ result->snapshot = g_db_snapshot_new_empty(result, result->collections);
if (result->snapshot == NULL)
goto error;
@@ -452,6 +449,47 @@ GCdbArchive *g_cdb_archive_new(const char *basedir, const char *tmpdir, const rl
/******************************************************************************
* *
* Paramètres : archive = informations quant à l'archive à interpréter. *
+* suffix = fin du nom de fichier à définir. *
+* *
+* Description : Construit un chemin pour un fichier propre à l'archive. *
+* *
+* Retour : Chemin de fichier à utiliser ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_cdb_archive_get_tmp_filename(const GCdbArchive *archive, const char *suffix)
+{
+ char *result; /* Chemin à retourner */
+ int ret; /* Retour d'un appel */
+
+ ret = asprintf(&result, "%s" G_DIR_SEPARATOR_S "%s_%s",
+ archive->tmpdir, get_rle_string(&archive->hash), suffix);
+
+ if (ret == -1)
+ result = NULL;
+
+ else
+ {
+ ret = ensure_path_exists(result);
+
+ if (ret == -1)
+ {
+ free(result);
+ result = NULL;
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : archive = informations quant à l'archive à interpréter. *
* *
* Description : Ouvre une archive avec tous les éléments à conserver. *
* *
@@ -501,8 +539,7 @@ static DBError g_cdb_archive_read(GCdbArchive *archive)
goto load_error;
}
- archive->snapshot = g_db_snapshot_new_from_xml(archive->tmpdir, get_rle_string(&archive->hash),
- xdoc, context);
+ archive->snapshot = g_db_snapshot_new_from_xml(archive, xdoc, context);
close_xml_file(xdoc, context);
@@ -529,7 +566,7 @@ static DBError g_cdb_archive_read(GCdbArchive *archive)
ret = archive_read_open_filename(in, archive->filename, 10240 /* ?! */);
if (ret != ARCHIVE_OK) goto bad_archive;
- status = g_db_snapshot_fill(archive->snapshot, in);
+ status = g_db_snapshot_fill(archive->snapshot, in, archive);
if (!status) goto load_error;
result = DBE_NONE;
@@ -1144,7 +1181,7 @@ static void *g_cdb_archive_process(GCdbArchive *archive)
case DBC_CREATE_SNAPSHOT:
- error = g_db_snapshot_create(archive->snapshot, archive->db);
+ error = g_db_snapshot_create(archive->snapshot, archive->db, archive);
if (error == DBE_NONE)
{
@@ -1548,7 +1585,6 @@ static bool g_cdb_archive_set_content(GCdbArchive *archive, packed_buffer_t *in_
GObjectStorage *storage; /* Gestionnaire de stockage */
GSerializableObject *content; /* Contenu restitué */
const gchar *hash; /* Empreinte de ce contenu */
- int ret; /* Retour d'un appel */
int fd; /* Flux ouvert en écriture */
bool status; /* Bilan d'une écriture */
@@ -1615,9 +1651,8 @@ static bool g_cdb_archive_set_content(GCdbArchive *archive, packed_buffer_t *in_
if (archive->cnt_file != NULL)
free(archive->cnt_file);
- ret = asprintf(&archive->cnt_file, "%s" G_DIR_SEPARATOR_S "%s_storedcontent.bin",
- archive->tmpdir, get_rle_string(&archive->hash));
- if (ret == -1)
+ archive->cnt_file = g_cdb_archive_get_tmp_filename(archive, "storedcontent.bin");
+ if (archive->cnt_file == NULL)
{
error = DBE_SYS_ERROR;
goto save_error;