aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-12 12:51:36 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-12 12:51:36 +0100
commit22e402a81372f328a72f1596efdc7c52571171bb (patch)
treea6c67b1086669953e6b315e4e54f017a7325d56d
parent3a201043a8eca6be7e7d9a8a06bf4ec18c4047ef (diff)
downloadrspamd-22e402a81372f328a72f1596efdc7c52571171bb.tar.gz
rspamd-22e402a81372f328a72f1596efdc7c52571171bb.zip
Fix converting of old storage.
-rw-r--r--src/fuzzy_storage.c2
-rw-r--r--src/libserver/fuzzy_backend.c54
2 files changed, 31 insertions, 25 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 5e89b9207..052cf64c9 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -385,7 +385,7 @@ start_fuzzy (struct rspamd_worker *worker)
if ((ctx->backend = rspamd_fuzzy_backend_open (ctx->hashfile, &err)) == NULL) {
- msg_err (err->message);
+ msg_err ("cannot open backend: %e", err);
g_error_free (err);
exit (EXIT_FAILURE);
}
diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c
index 0d7ce9485..c59fa6133 100644
--- a/src/libserver/fuzzy_backend.c
+++ b/src/libserver/fuzzy_backend.c
@@ -433,37 +433,43 @@ rspamd_fuzzy_backend_convert (const gchar *path, int fd, GError **err)
(void)lseek (fd, 0, SEEK_SET);
off = sizeof (FUZZY_FILE_MAGIC);
- if ((map = mmap (NULL, st.st_size - off, PROT_READ, MAP_SHARED, fd,
- 0)) == MAP_FAILED) {
- g_set_error (err, rspamd_fuzzy_backend_quark (),
- errno, "Cannot mmap file %s: %s",
- path, strerror (errno));
- rspamd_fuzzy_backend_close (nbackend);
-
- return FALSE;
+ if (off >= st.st_size) {
+ msg_warn ("old fuzzy storage is empty or corrupted, remove it");
}
+ else {
+ if ((map = mmap (NULL, st.st_size - off, PROT_READ, MAP_SHARED, fd,
+ 0)) == MAP_FAILED) {
+ g_set_error (err, rspamd_fuzzy_backend_quark (),
+ errno, "Cannot mmap file %s: %s",
+ path, strerror (errno));
+ rspamd_fuzzy_backend_close (nbackend);
- end = map + st.st_size;
- p = map + off;
+ return FALSE;
+ }
- rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_START,
+ end = map + st.st_size;
+ p = map + off;
+
+ rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_START,
nbackend, NULL);
- while (p < end) {
- n = (struct rspamd_legacy_fuzzy_node *)p;
- /* Convert node flag, digest, value, time */
- if (rspamd_fuzzy_backend_run_stmt (nbackend, RSPAMD_FUZZY_BACKEND_INSERT,
- (gint)n->flag, n->h.hash_pipe,
- (gint64)n->value, n->time) != SQLITE_OK) {
- msg_warn ("Cannot execute init sql %s: %s",
- prepared_stmts[RSPAMD_FUZZY_BACKEND_INSERT].sql,
- sqlite3_errmsg (nbackend->db));
+ while (p < end) {
+ n = (struct rspamd_legacy_fuzzy_node *)p;
+ /* Convert node flag, digest, value, time */
+ if (rspamd_fuzzy_backend_run_stmt (nbackend, RSPAMD_FUZZY_BACKEND_INSERT,
+ (gint)n->flag, n->h.hash_pipe,
+ (gint64)n->value, n->time) != SQLITE_OK) {
+ msg_warn ("Cannot execute init sql %s: %s",
+ prepared_stmts[RSPAMD_FUZZY_BACKEND_INSERT].sql,
+ sqlite3_errmsg (nbackend->db));
+ }
+ p += sizeof (struct rspamd_legacy_fuzzy_node);
}
- p += sizeof (struct rspamd_legacy_fuzzy_node);
+
+ munmap (map, st.st_size);
+ rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_COMMIT,
+ nbackend, NULL);
}
- munmap (map, st.st_size);
- rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_COMMIT,
- nbackend, NULL);
rspamd_fuzzy_backend_run_sql (create_index_sql, nbackend, NULL);
rspamd_fuzzy_backend_close (nbackend);
rename (tmpdb, path);