From 92fadcdf4eea2515e8358ef2d1c7b01430c3b0bb Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 25 Apr 2019 18:23:17 +0200 Subject: [PATCH] mod_spam_filter: Auto-create dump directory If the directory holding the specified "spam_dump_file" doesn't exist, create it on startup. --- mod_spam_filter/src/mod_spam_filter.erl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mod_spam_filter/src/mod_spam_filter.erl b/mod_spam_filter/src/mod_spam_filter.erl index 98ebdff..6ddfd84 100644 --- a/mod_spam_filter/src/mod_spam_filter.erl +++ b/mod_spam_filter/src/mod_spam_filter.erl @@ -157,12 +157,19 @@ init([Host, Opts]) -> DumpFd = if DumpFile == none -> undefined; true -> + case filelib:ensure_dir(DumpFile) of + ok -> + ok; + {error, Reason} -> + Dirname = filename:dirname(DumpFile), + throw({open, Dirname, Reason}) + end, Modes = [append, raw, binary, delayed_write], case file:open(DumpFile, Modes) of {ok, Fd} -> Fd; - {error, Reason} -> - throw({open, DumpFile, Reason}) + {error, Reason1} -> + throw({open, DumpFile, Reason1}) end end, {ok, #state{host = Host,