From a85054581e61f3871bf3e02c0a4e4fdca1a3b1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Turnel?= Date: Fri, 13 Apr 2018 10:10:40 +0200 Subject: [PATCH] Fix ZRTP file renaming while still in use (retrofit of commit ccb308) --- coreapi/linphonecore.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 15e9e422b..796e82d82 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6485,10 +6485,21 @@ void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){ /* rename the newly created sqlite3 file in to the given file name */ rename(file, bkpFile); + +#ifdef _WIN32 + /* We first have to close the file before renaming it */ + sqlite3_close(lc->zrtp_cache_db); +#endif + if (rename(tmpFile, file)==0) { /* set the flag if we were able to set the sqlite file in the correct place (even if migration failed) */ lp_config_set_int(lc->config, "sip", "zrtp_cache_migration_done", TRUE); } +#ifdef _WIN32 + /* Then reopen it */ + _linphone_sqlite3_open(file, &lc->zrtp_cache_db); +#endif + /* clean up */ bctbx_free(bkpFile); xmlFree(cacheXml);