From: Christophe Romain Date: Thu, 31 Jan 2019 12:25:56 +0000 (+0100) Subject: Do not overwrite odbc config file (#2295) X-Git-Tag: 19.02~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae7b391657512560e62e8182dee4cf76b0f04e98;p=ejabberd Do not overwrite odbc config file (#2295) --- diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 153479026..2d9c64187 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -1071,9 +1071,9 @@ init_mssql(Host) -> case filelib:ensure_dir(freetds_config()) of ok -> try - ok = file:write_file(freetds_config(), FreeTDS, [append]), - ok = file:write_file(odbcinst_config(), ODBCINST), - ok = file:write_file(odbc_config(), ODBCINI, [append]), + ok = write_file_if_new(freetds_config(), FreeTDS), + ok = write_file_if_new(odbcinst_config(), ODBCINST), + ok = write_file_if_new(odbc_config(), ODBCINI), os:putenv("ODBCSYSINI", tmp_dir()), os:putenv("FREETDS", freetds_config()), os:putenv("FREETDSCONF", freetds_config()), @@ -1089,6 +1089,12 @@ init_mssql(Host) -> Err end. +write_file_if_new(File, Payload) -> + case filelib:is_file(File) of + true -> ok; + false -> file:write_file(File, Payload) + end. + tmp_dir() -> case os:type() of {win32, _} -> filename:join([os:getenv("HOME"), "conf"]);