diff options
Diffstat (limited to 'src/analysis/db/cdb.c')
-rw-r--r-- | src/analysis/db/cdb.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/analysis/db/cdb.c b/src/analysis/db/cdb.c index 563aa40..55d1b2d 100644 --- a/src/analysis/db/cdb.c +++ b/src/analysis/db/cdb.c @@ -34,7 +34,6 @@ #include <pthread.h> #include <signal.h> #include <stdio.h> -#include <sqlite3.h> #include <string.h> #include <unistd.h> #include <sys/stat.h> @@ -283,6 +282,8 @@ GCdbArchive *g_cdb_archive_new(const char *owner, const rle_string *hash, const result->filename = get_xdg_config_dir(suffix); + printf("dealing with '%s'...\n", result->filename); + free(suffix); if (!mkpath(result->filename)) @@ -318,7 +319,7 @@ GCdbArchive *g_cdb_archive_new(const char *owner, const rle_string *hash, const g_cdb_archive_create_xml_desc(result, user); g_cdb_archive_create_db(result, NULL); - if (!g_cdb_archive_write(result)) + if (g_cdb_archive_write(result) != DBE_NONE) goto gcan_error; } @@ -473,13 +474,13 @@ static bool g_cdb_archive_read(GCdbArchive *archive) * * ******************************************************************************/ -bool g_cdb_archive_write(const GCdbArchive *archive) +DBError g_cdb_archive_write(const GCdbArchive *archive) { - bool result; /* Conclusion à retourner */ + DBError result; /* Conclusion à retourner */ struct archive *out; /* Archive à constituer */ int ret; /* Bilan d'un appel */ - result = false; + result = DBE_ARCHIVE_ERROR; out = archive_write_new(); archive_write_add_filter_xz(out); @@ -488,16 +489,19 @@ bool g_cdb_archive_write(const GCdbArchive *archive) ret = archive_write_open_filename(out, archive->filename); if (ret != ARCHIVE_OK) goto gcaw_exit; - bool add_file_to_archive(struct archive *out, const char *src, const char *path) + 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; + ret = stat(src, &info); - if (ret != 0) return false; + if (ret != 0) return DBE_SYS_ERROR; entry = archive_entry_new(); @@ -508,7 +512,11 @@ bool g_cdb_archive_write(const GCdbArchive *archive) if (ret != 0) goto afta_error; fd = open(src, O_RDONLY); - if (fd == -1) goto afta_error; + if (fd == -1) + { + status = DBE_SYS_ERROR; + goto afta_error; + } for (len = safe_read(fd, buffer, ARCHIVE_RBUF_SIZE); len > 0; @@ -522,18 +530,20 @@ bool g_cdb_archive_write(const GCdbArchive *archive) archive_entry_free(entry); - return true; + return DBE_NONE; afta_error: archive_entry_free(entry); - return false; + return status; } result = add_file_to_archive(out, archive->xml_desc, "desc.xml"); - result &= add_file_to_archive(out, archive->sql_db, "sql.db"); + + if (result == DBE_NONE) + result = add_file_to_archive(out, archive->sql_db, "sql.db"); gcaw_exit: @@ -781,6 +791,7 @@ static void *g_cdb_archive_process(GCdbArchive *archive) uint32_t val32; /* Valeur sur 32 bits */ bool status; /* Bilan de lecture initiale */ uint32_t command; /* Commande de la requête */ + DBError error; /* Bilan d'une opération */ GDbCollection *collec; /* Collection visée au final */ void interrupt_poll_with_sigusr1(int sig) { }; @@ -843,6 +854,18 @@ static void *g_cdb_archive_process(GCdbArchive *archive) switch (command) { + case DBC_SAVE: + + error = g_cdb_archive_write(archive); + + if (!safe_send(fds[i].fd, (uint32_t []) { htobe32(DBC_SAVE) }, sizeof(uint32_t), 0)) + goto gcap_bad_exchange; + + if (!safe_send(fds[i].fd, (uint32_t []) { htobe32(error) }, sizeof(uint32_t), 0)) + goto gcap_bad_exchange; + + break; + case DBC_COLLECTION: status = safe_recv(fds[i].fd, &val32, sizeof(uint32_t), 0); @@ -851,7 +874,7 @@ static void *g_cdb_archive_process(GCdbArchive *archive) collec = find_collection_in_list(archive->collections, be32toh(val32)); if (collec == NULL) goto gcap_bad_exchange; - status = g_db_collection_recv(collec, fds[i].fd); + status = g_db_collection_recv(collec, fds[i].fd, archive->db); if (!status) goto gcap_bad_exchange; printf("## CDB ## Got something for collection %p...\n", collec); |