engine: avoid flipping configdate

The engine gets instantiated twice: once for logging, once for
syncing. The config generated in each case is different because
sources only become active for syncing. Therefore the config change
check unnecessarily triggered during each sync (first getConfigXML
call created one hash, then the second another), causing DevInf to be
sent unnecessarily and always rewriting the .ini file.

The check is only needed when instantiating the engine that is getting
used for syncing. However, the config date must always be valid.
This commit is contained in:
Patrick Ohly 2014-08-29 11:18:03 +02:00
parent 9581b682a4
commit a9f265971b
2 changed files with 21 additions and 13 deletions

View File

@ -2505,7 +2505,7 @@ void SyncContext::getConfigTemplateXML(const string &mode,
}
}
void SyncContext::getConfigXML(string &xml, string &configname)
void SyncContext::getConfigXML(bool isSync, string &xml, string &configname)
{
string rules;
getConfigTemplateXML(m_serverMode ? "server" : "client",
@ -2975,13 +2975,18 @@ void SyncContext::getConfigXML(string &xml, string &configname)
substTag(xml, "defaultauth", getClientAuthType());
}
// if the hash code is changed, that means the content of the
// config has changed, save the new hash and regen the configdate
hash = Hash(xml.c_str());
if (getHashCode() != hash) {
setConfigDate();
setHashCode(hash);
flush();
if (isSync ||
!getConfigDate().wasSet()) {
// If the hash code of the main sync XML config is changed, that
// means the content of the config has changed. Save the new hash
// and regen the configdate. Also necessary when no config data
// has ever been set.
hash = Hash(xml.c_str());
if (getHashCode() != hash) {
setConfigDate();
setHashCode(hash);
flush();
}
}
substTag(xml, "configdate", getConfigDate().c_str());
}
@ -3085,10 +3090,10 @@ SyncContext::analyzeSyncMLMessage(const char *data, size_t len,
return info;
}
void SyncContext::initEngine(bool logXML)
void SyncContext::initEngine(bool isSync)
{
string xml, configname;
getConfigXML(xml, configname);
getConfigXML(isSync, xml, configname);
try {
m_engine.InitEngineXML(xml.c_str());
} catch (const BadSynthesisResult &ex) {
@ -3100,7 +3105,7 @@ void SyncContext::initEngine(bool logXML)
xml.c_str());
throw;
}
if (logXML &&
if (isSync &&
getLogLevel() >= 5) {
SE_LOG_DEV(NULL, "Full XML configuration:\n%s", xml.c_str());
}

View File

@ -533,10 +533,11 @@ class SyncContext : public SyncConfig {
* Calls getConfigTemplateXML(), then fills in
* sync source XML fragments if necessary.
*
* @param isSync the XML config will be used for the final engine used for syncing, not just logging
* @retval xml is filled with complete Synthesis client config
* @retval configname a string describing where the config came from
*/
virtual void getConfigXML(string &xml, string &configname);
virtual void getConfigXML(bool isSync, string &xml, string &configname);
/**
* Callback for derived classes: called after initializing the
@ -646,8 +647,10 @@ class SyncContext : public SyncConfig {
/**
* generate XML configuration and (re)initialize engine with it
*
* @param isSync the XML config will be used for the final engine used for syncing, not just logging
*/
void initEngine(bool logXML);
void initEngine(bool isSync);
/**
* the code common to init() and status():