aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-27 15:09:53 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-27 15:09:53 +0100
commit627cf5036cabead89f5c6162d3db23ae552c9694 (patch)
treeb1f8853073ce8adc982a9f81c4cd3da5d10858a6 /src/plugins
parent5bcdb685d29c217866e122b9455afd26c3301015 (diff)
downloadrspamd-627cf5036cabead89f5c6162d3db23ae552c9694.tar.gz
rspamd-627cf5036cabead89f5c6162d3db23ae552c9694.zip
[Feature] Lock ANN file when loading
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/lua/fann_scores.lua19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/plugins/lua/fann_scores.lua b/src/plugins/lua/fann_scores.lua
index ea82974a1..e72c1d4d6 100644
--- a/src/plugins/lua/fann_scores.lua
+++ b/src/plugins/lua/fann_scores.lua
@@ -75,7 +75,9 @@ local function load_fann(id)
return false
end
+ local fd = rspamd_util.lock_file(fname)
data[id].fann = rspamd_fann.load(fname)
+ rspamd_util.unlock_file(fd) -- closes fd
if data[id].fann then
local n = rspamd_config:get_symbols_count()
@@ -182,7 +184,22 @@ local function fann_train_callback(score, required_score,results, cf, id, opts)
if data[id].ntrains > max_trains then
-- Store fann on disk
- local res = data[id].fann_train:save(fname)
+ local res = false
+
+ if not rspamd_util.stat(fname) then
+ local fd,err = rspamd_util.create_file(fname)
+ if not fd then
+ rspamd_logger.errx(cf, 'cannot save fann in %s: %s', fname, err)
+ else
+ rspamd_util.lock_file(fname, fd)
+ res = data[id].fann_train:save(fname)
+ rspamd_util.unlock_file(fd) -- Closes fd as well
+ end
+ else
+ local fd = rspamd_util.lock_file(fname)
+ res = data[id].fann_train:save(fname)
+ rspamd_util.unlock_file(fd) -- Closes fd as well
+ end
if not res then
rspamd_logger.errx(cf, 'cannot save fann in %s', fname)