summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/db/cdb.c131
1 files changed, 31 insertions, 100 deletions
diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c
index 9479b4d..bcd3ed3 100644
--- a/src/analysis/db/cdb.c
+++ b/src/analysis/db/cdb.c
@@ -24,11 +24,8 @@
#include "cdb.h"
-#include <archive.h>
-#include <archive_entry.h>
#include <assert.h>
#include <errno.h>
-#include <fcntl.h>
#include <malloc.h>
#include <poll.h>
#include <pthread.h>
@@ -46,9 +43,9 @@
#include "collection.h"
#include "protocol.h"
+#include "../../common/compression.h"
#include "../../common/cpp.h"
#include "../../common/extstr.h"
-#include "../../common/io.h"
#include "../../common/pathname.h"
#include "../../common/xml.h"
#include "../../core/collections.h"
@@ -56,11 +53,6 @@
-/* Fixe le tampon pour la lecture des fichiers à inclure */
-#define ARCHIVE_RBUF_SIZE 2048
-
-
-
/* Informations relatives à un client */
typedef struct _cdb_client
{
@@ -413,8 +405,6 @@ static bool g_cdb_archive_read(GCdbArchive *archive)
bool result; /* Conclusion à retourner */
struct archive *in; /* Archive à consulter */
int ret; /* Bilan d'un appel */
- int flags; /* Propriétés à extraire */
- struct archive *out; /* Extracteur générique */
struct archive_entry *entry; /* Elément de l'archive */
const char *path; /* Désignation d'un fichier */
@@ -427,54 +417,15 @@ static bool g_cdb_archive_read(GCdbArchive *archive)
ret = archive_read_open_filename(in, archive->filename, 10240 /* ?! */);
if (ret != ARCHIVE_OK) goto gcar_exit;
- /* Propriétés à restaurer */
- flags = ARCHIVE_EXTRACT_TIME;
- flags |= ARCHIVE_EXTRACT_PERM;
- flags |= ARCHIVE_EXTRACT_ACL;
- flags |= ARCHIVE_EXTRACT_FFLAGS;
-
- out = archive_write_disk_new();
- archive_write_disk_set_options(out, flags);
- archive_write_disk_set_standard_lookup(out);
-
for (ret = archive_read_next_header(in, &entry);
ret == ARCHIVE_OK;
ret = archive_read_next_header(in, &entry))
{
- bool dump_arch_data(struct archive_entry *ent, struct archive *input, struct archive *output)
- {
- const void *buff; /* Tampon de copie */
- size_t size; /* Quantité copiée */
- __LA_INT64_T offset; /* Position de lecture */
-
- ret = archive_write_header(output, entry);
- if (ret != ARCHIVE_OK) return false;
-
- for (ret = archive_read_data_block(input, &buff, &size, &offset);
- ret == ARCHIVE_OK;
- ret = archive_read_data_block(input, &buff, &size, &offset))
- {
- ret = archive_write_data_block(output, buff, size, offset);
- if (ret != ARCHIVE_OK)
- return false;
- }
-
- if (ret != ARCHIVE_EOF)
- return false;
-
- ret = archive_write_finish_entry(output);
-
- return (ret == ARCHIVE_OK);
-
- }
-
path = archive_entry_pathname(entry);
if (strcmp(path, "desc.xml") == 0)
{
- archive_entry_set_pathname(entry, archive->xml_desc);
-
- if (!dump_arch_data(entry, in, out))
+ if (!dump_archive_entry_into_file(in, entry, archive->xml_desc))
goto gcar_exit;
if (!open_xml_file(archive->xml_desc, &archive->xdoc, &archive->context))
@@ -483,9 +434,7 @@ static bool g_cdb_archive_read(GCdbArchive *archive)
}
else if (strcmp(path, "sql.db") == 0)
{
- archive_entry_set_pathname(entry, archive->sql_db);
-
- if (!dump_arch_data(entry, in, out))
+ if (!dump_archive_entry_into_file(in, entry, archive->sql_db))
goto gcar_exit;
ret = sqlite3_open(archive->sql_db, &archive->db);
@@ -499,9 +448,6 @@ static bool g_cdb_archive_read(GCdbArchive *archive)
archive_read_close(in);
archive_read_free(in);
- archive_write_close(out);
- archive_write_free(out);
-
result = true;
gcar_exit:
@@ -528,6 +474,7 @@ DBError g_cdb_archive_write(const GCdbArchive *archive)
DBError result; /* Conclusion à retourner */
struct archive *out; /* Archive à constituer */
int ret; /* Bilan d'un appel */
+ CPError status; /* Bilan d'une compression */
result = DBE_ARCHIVE_ERROR;
@@ -538,62 +485,46 @@ DBError g_cdb_archive_write(const GCdbArchive *archive)
ret = archive_write_open_filename(out, archive->filename);
if (ret != ARCHIVE_OK) goto gcaw_exit;
- DBError add_file_to_archive(struct archive *out, const char *src, const char *path)
- {
- DBError status; /* Bilan à renvoyer */
- struct stat info; /* Informations d'origine */
- struct archive_entry *entry; /* Elément de l'archive */
- int fd; /* Flux ouvert en lecture */
- char buffer[ARCHIVE_RBUF_SIZE]; /* Tampon pour les transferts */
- ssize_t len; /* Quantité de données lues */
-
- status = DBE_ARCHIVE_ERROR;
+ status = add_file_into_archive(out, archive->xml_desc, "desc.xml");
- ret = stat(src, &info);
- if (ret != 0) return DBE_SYS_ERROR;
+ switch (status)
+ {
+ case CPE_NO_ERROR:
+ result = DBE_NONE;
+ break;
- entry = archive_entry_new();
+ case CPE_SYSTEM_ERROR:
+ result = DBE_SYS_ERROR;
+ break;
- archive_entry_copy_stat(entry, &info);
- archive_entry_set_pathname(entry, path);
+ case CPE_ARCHIVE_ERROR:
+ result = DBE_ARCHIVE_ERROR;
+ break;
- ret = archive_write_header(out, entry);
- if (ret != 0) goto afta_error;
+ }
- fd = open(src, O_RDONLY);
- if (fd == -1)
- {
- status = DBE_SYS_ERROR;
- goto afta_error;
- }
+ if (result == DBE_NONE)
+ {
+ status = add_file_into_archive(out, archive->sql_db, "sql.db");
- for (len = safe_read_partial(fd, buffer, ARCHIVE_RBUF_SIZE);
- len > 0;
- len = safe_read_partial(fd, buffer, ARCHIVE_RBUF_SIZE))
+ switch (status)
{
- if (archive_write_data(out, buffer, len) != len)
- goto afta_error;
- }
-
- close(fd);
-
- archive_entry_free(entry);
-
- return DBE_NONE;
+ case CPE_NO_ERROR:
+ result = DBE_NONE;
+ break;
- afta_error:
+ case CPE_SYSTEM_ERROR:
+ result = DBE_SYS_ERROR;
+ break;
- archive_entry_free(entry);
+ case CPE_ARCHIVE_ERROR:
+ result = DBE_ARCHIVE_ERROR;
+ break;
- return status;
+ }
}
- result = add_file_to_archive(out, archive->xml_desc, "desc.xml");
-
- if (result == DBE_NONE)
- result = add_file_to_archive(out, archive->sql_db, "sql.db");
-
gcaw_exit:
archive_write_free(out);