ReloadableXMLFile::ReloadableXMLFile(const DOMElement* e, Category& log)
- : m_root(e), m_local(true), m_validate(false), m_filestamp(0), m_reloadInterval(0), m_lock(NULL), m_log(log),
+ : m_root(e), m_local(true), m_validate(false), m_backupIndicator(true), m_filestamp(0), m_reloadInterval(0), m_lock(NULL), m_log(log),
m_shutdown(false), m_reload_wait(NULL), m_reload_thread(NULL)
{
#ifdef _DEBUG
auto_ptr_char temp2(source);
m_backing=temp2.get();
XMLToolingConfig::getConfig().getPathResolver()->resolve(m_backing, PathResolver::XMLTOOLING_RUN_FILE);
- log.debug("backup remote resource with (%s)", m_backing.c_str());
+ log.debug("backup remote resource to (%s)", m_backing.c_str());
}
source = e->getAttributeNS(NULL,reloadInterval);
if (source && *source) {
DOMDocument* doc=NULL;
if (m_local || backup) {
auto_ptr_XMLCh widenit(backup ? m_backing.c_str() : m_source.c_str());
+ // Use library-wide lock for now, nothing else is using it anyway.
+ Locker locker(backup ? getBackupLock() : NULL);
LocalFileInputSource src(widenit.get());
Wrapper4InputSource dsrc(&src, false);
if (m_validate)
m_log.infoStream() << "loaded XML resource (" << (backup ? m_backing : m_source) << ")" << logging::eol;
if (!backup && !m_backing.empty()) {
- m_log.debug("backing up remote resource to (%s)", m_backing.c_str());
- try {
- ofstream backer(m_backing.c_str());
- backer << *doc;
+ // If the indicator is true, we're responsible for the backup.
+ if (m_backupIndicator) {
+ m_log.debug("backing up remote resource to (%s)", m_backing.c_str());
+ try {
+ Locker locker(getBackupLock());
+ ofstream backer(m_backing.c_str());
+ backer << *doc;
+ }
+ catch (exception& ex) {
+ m_log.crit("exception while backing up resource: %s", ex.what());
+ }
}
- catch (exception& ex) {
- m_log.crit("exception while backing up resource: %s", ex.what());
+ else {
+ // If the indicator was false, set true to signal that a backup is needed.
+ // The caller will presumably flip it back to false once that's done.
+ m_backupIndicator = true;
}
}
{
// If this method isn't overridden, we acquire a write lock
// and just call the old override.
- m_lock->wrlock();
+ if (m_lock)
+ m_lock->wrlock();
SharedLock locker(m_lock, false);
return load();
}
+
+Lockable* ReloadableXMLFile::getBackupLock()
+{
+ return &XMLToolingConfig::getConfig();
+}