[xmltooling] 29/65: SSPCPP-684 ReloadableXMLFile can save to a file as it loads
Ferenc Wágner
wferi-guest at moszumanska.debian.org
Thu Jun 30 13:07:37 UTC 2016
This is an automated email from the git hooks/post-receive script.
wferi-guest pushed a commit to branch debian/master
in repository xmltooling.
commit de7c587477063649dcb01fb39cff2f5e06e92ccb
Author: Rod Widdowson <rdw at steadingsoftware.com>
Date: Sun Jun 5 15:47:01 2016 +0100
SSPCPP-684 ReloadableXMLFile can save to a file as it loads
https://issues.shibboleth.net/jira/browse/SSPCPP-684
If asked, ReloadableXMLFile will save to a file as it
downloads from a URL. We use the changes to CURLInputStream
---
.gitignore | 2 ++
xmltooling/util/ReloadableXMLFile.cpp | 22 ++++++++++++++++++++--
xmltooling/util/ReloadableXMLFile.h | 14 +++++++++++++-
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0acb2e0..4f9abe1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,3 +70,5 @@ xmltooling-lite-Release
/schemas/catalog.xml
/xmltooling/config_pub.h
/xmltoolingtest/xmltoolingtest
+/xmltoolingtest/data/*bak
+/xmltoolingtest/data/clonedfile.xml
\ No newline at end of file
diff --git a/xmltooling/util/ReloadableXMLFile.cpp b/xmltooling/util/ReloadableXMLFile.cpp
index aae5990..984f84e 100644
--- a/xmltooling/util/ReloadableXMLFile.cpp
+++ b/xmltooling/util/ReloadableXMLFile.cpp
@@ -372,7 +372,12 @@ void ReloadableXMLFile::unlock()
m_lock->unlock();
}
-pair<bool,DOMElement*> ReloadableXMLFile::load(bool backup)
+pair<bool, DOMElement*> ReloadableXMLFile::load(bool backup)
+{
+ return load(backup, "");
+}
+
+pair<bool,DOMElement*> ReloadableXMLFile::load(bool backup, string backingFile)
{
#ifdef _DEBUG
NDC ndc("load");
@@ -391,6 +396,12 @@ pair<bool,DOMElement*> ReloadableXMLFile::load(bool backup)
else
m_log.debug("loading configuration from external resource...");
+ if (!backingFile.empty() && backup)
+ m_log.error("Internal error: backing file provided to backup load");
+
+ if (!backingFile.empty())
+ m_log.debug("writing to backing file " + backingFile);
+
DOMDocument* doc=nullptr;
if (m_local || backup) {
auto_ptr_XMLCh widenit(backup ? m_backing.c_str() : m_source.c_str());
@@ -404,7 +415,7 @@ pair<bool,DOMElement*> ReloadableXMLFile::load(bool backup)
doc=XMLToolingConfig::getConfig().getParser().parse(dsrc);
}
else {
- URLInputSource src(m_root, nullptr, &m_cacheTag);
+ URLInputSource src(m_root, nullptr, &m_cacheTag, backingFile);
Wrapper4InputSource dsrc(&src, false);
if (m_validate)
doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc);
@@ -451,11 +462,18 @@ pair<bool,DOMElement*> ReloadableXMLFile::load(bool backup)
auto_ptr_char msg(e.getMessage());
m_log.errorStream() << "Xerces error while loading resource (" << (backup ? m_backing : m_source) << "): "
<< msg.get() << logging::eol;
+ // Cleanup if we left anything in fligbt
+ if (!backingFile.empty() && !backup)
+ remove(backingFile.c_str());
+
throw XMLParserException(msg.get());
}
catch (exception& e) {
m_log.errorStream() << "error while loading resource ("
<< (m_source.empty() ? "inline" : (backup ? m_backing : m_source)) << "): " << e.what() << logging::eol;
+ // Cleanup if we left anything in fligbt
+ if (!backingFile.empty() && !backup)
+ remove(backingFile.c_str());
throw;
}
}
diff --git a/xmltooling/util/ReloadableXMLFile.h b/xmltooling/util/ReloadableXMLFile.h
index d7cf55e..8f4630e 100644
--- a/xmltooling/util/ReloadableXMLFile.h
+++ b/xmltooling/util/ReloadableXMLFile.h
@@ -138,11 +138,23 @@ namespace xmltooling {
* backup for remote resources, which allows additional validation to be
* performed besides just successful XML parsing.
*
- * @param backup true iff the backup source should be loaded
+ * <p>Anyone calling this code needs to take ownership of the job of creating
+ * the backup (if the inpout is well formed). As an assist, providing
+ * a unique file name as the second parameter causes the input source to be
+ * copied to this file. Thus input cna be done without locking and the
+ * job of creating the backup consists of doign a rename (under the lock).
+ *
+ * <p> The single parameter version is deprecated and is the same as
+ * calling with an empty string at the second parameter (which means
+ * no backing file).
+ *
+ * @param backup true iff the backup source should be loaded
+ * @param backingFile Filoe name to copy the input to.
* @return a pair consisting of a flag indicating whether to take ownership of
* the document, and the root element of the tree to load
*/
virtual std::pair<bool,xercesc::DOMElement*> load(bool backup);
+ virtual std::pair<bool, xercesc::DOMElement*> load(bool backup, std::string backingFile);
/**
* Accesses a lock interface protecting use of backup file associated with the
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/xmltooling.git
More information about the Pkg-shibboleth-devel
mailing list