diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-27 15:09:53 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-27 15:09:53 +0100 |
commit | 627cf5036cabead89f5c6162d3db23ae552c9694 (patch) | |
tree | b1f8853073ce8adc982a9f81c4cd3da5d10858a6 /src/plugins | |
parent | 5bcdb685d29c217866e122b9455afd26c3301015 (diff) | |
download | rspamd-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.lua | 19 |
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) |