diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-29 13:54:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-29 13:54:58 +0100 |
commit | 62b8b657d9d07844b8b72d21df5b8e66ee84ac43 (patch) | |
tree | 9a5ccdd08119128a16bbc35e7d635fa495f26827 /src/hs_helper.c | |
parent | 6ccd44320e725ed542883491af7d6b17a2f4a6eb (diff) | |
download | rspamd-62b8b657d9d07844b8b72d21df5b8e66ee84ac43.tar.gz rspamd-62b8b657d9d07844b8b72d21df5b8e66ee84ac43.zip |
[Fix] Ensure that hyperscan cache written is written properly
Diffstat (limited to 'src/hs_helper.c')
-rw-r--r-- | src/hs_helper.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/hs_helper.c b/src/hs_helper.c index 127cf2785..d2bcf891b 100644 --- a/src/hs_helper.c +++ b/src/hs_helper.c @@ -127,11 +127,11 @@ rspamd_hs_helper_cleanup_dir (struct hs_helper_ctx *ctx, gboolean forced) } globbuf.gl_offs = 0; - len = strlen (ctx->hs_dir) + 1 + sizeof ("*.hs"); + len = strlen (ctx->hs_dir) + 1 + sizeof ("*.hs.new") + 2; pattern = g_malloc (len); rspamd_snprintf (pattern, len, "%s%c%s", ctx->hs_dir, G_DIR_SEPARATOR, "*.hs"); - if ((rc = glob (pattern, GLOB_DOOFFS, NULL, &globbuf)) == 0) { + if ((rc = glob (pattern, 0, NULL, &globbuf)) == 0) { for (i = 0; i < globbuf.gl_pathc; i++) { if (forced || !rspamd_re_cache_is_valid_hyperscan_file (ctx->cfg->re_cache, @@ -150,6 +150,24 @@ rspamd_hs_helper_cleanup_dir (struct hs_helper_ctx *ctx, gboolean forced) } globfree (&globbuf); + + memset (&globbuf, 0, sizeof (globbuf)); + rspamd_snprintf (pattern, len, "%s%c%s", ctx->hs_dir, G_DIR_SEPARATOR, "*.hs.new"); + if ((rc = glob (pattern, 0, NULL, &globbuf)) == 0) { + for (i = 0; i < globbuf.gl_pathc; i++) { + if (unlink (globbuf.gl_pathv[i]) == -1) { + msg_err ("cannot unlink %s: %s", globbuf.gl_pathv[i], + strerror (errno)); + ret = FALSE; + } + } + } + else if (rc != GLOB_NOMATCH) { + msg_err ("glob %s failed: %s", pattern, strerror (errno)); + ret = FALSE; + } + + globfree (&globbuf); g_free (pattern); return ret; |