enabled = false;
autorefresh = false;
};
-
+
bool enabled;
bool autorefresh;
std::string product_dir;
#include <list>
+#include <zypp/target/store/xml/XMLSourceCacheParser.h>
+
#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
#include "boost/filesystem/fstream.hpp" // ditto
{
DBG << "[source-cache] - " << dir_itr->leaf() << std::endl;
//sources.insert( sourceDataFromCacheFile( source_p + "/" + dir_itr->leaf() ) );
- PersistentStorage::SourceData data;
- sources.push_back(data);
+ std::string full_path = (source_p / dir_itr->leaf()).string();
+ std::ifstream anIstream(full_path.c_str());
+ XMLSourceCacheParser iter(anIstream, "");
+ for (; ! iter.atEnd(); ++iter) {
+ PersistentStorage::SourceData data = **iter;
+ sources.push_back(data);
+ }
}
MIL << "done reading source cache" << std::endl;
return sources;
SUBDIRS =
+INCLUDES = -I$(oldincludedir)/libxml2 -I..
+
## ##################################################
targetxmlincludedir = $(pkgincludedir)/target/store/xml
XMLScriptImpl.h \
XMLSelectionImpl.h \
XMLPatternImpl.h \
- XMLProductImpl.h
+ XMLProductImpl.h \
+ XMLSourceCacheParser.h
noinst_LTLIBRARIES = lib@PACKAGE@_target_xml.la
XMLScriptImpl.cc \
XMLSelectionImpl.cc \
XMLPatternImpl.cc \
- XMLProductImpl.cc
+ XMLProductImpl.cc \
+ XMLSourceCacheParser.cc
## ##################################################
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/store/xml/XMLSourceCacheParser.cc
+ *
+*/
+
+#include <zypp/parser/LibXMLHelper.h>
+#include <istream>
+#include <string>
+#include <cassert>
+#include <libxml/xmlreader.h>
+#include <libxml/tree.h>
+#include <zypp/base/Logger.h>
+//#include <zypp/parser/yum/schemanames.h>
+
+#include <zypp/target/store/xml/XMLSourceCacheParser.h>
+
+using namespace std;
+
+namespace zypp {
+ namespace storage {
+
+ XMLSourceCacheParser::XMLSourceCacheParser()
+ { }
+
+ XMLSourceCacheParser::XMLSourceCacheParser(SourceData_Ptr& entry)
+ : zypp::parser::XMLNodeIterator<SourceData_Ptr>(entry)
+ { }
+
+
+ XMLSourceCacheParser::~XMLSourceCacheParser()
+ { }
+
+
+ // select for which elements process() will be called
+ bool
+ XMLSourceCacheParser::isInterested(const xmlNodePtr nodePtr)
+ {
+ return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "source-cache";
+ }
+
+ // do the actual processing
+ SourceData_Ptr
+ XMLSourceCacheParser::process(const xmlTextReaderPtr reader)
+ {
+ assert(reader);
+ SourceData_Ptr dataPtr = new PersistentStorage::SourceData;
+ xmlNodePtr dataNode = xmlTextReaderExpand(reader);
+ assert(dataNode);
+
+ for (xmlNodePtr child = dataNode->children; child && child != dataNode; child = child->next)
+ {
+ if (_helper.isElement(child))
+ {
+ string name = _helper.name(child);
+ if (name == "enabled")
+ {
+ dataPtr->enabled = (_helper.content(child) == "true") ? true : false;
+ }
+ else if (name == "auto-refresh")
+ {
+ dataPtr->autorefresh = (_helper.content(child) == "true") ? true : false;
+ }
+ else if (name == "type")
+ {
+ dataPtr->type = _helper.content(child);
+ }
+ else if (name == "product-dir")
+ {
+ dataPtr->product_dir = _helper.content(child);
+ }
+ else if (name == "alias")
+ {
+ dataPtr->alias = _helper.content(child);
+ }
+ else if (name == "url")
+ {
+ dataPtr->url = _helper.content(child);
+ }
+ else
+ {
+ WAR << "SourceCache entry contains the unknown element <" << name << "> "
+ << _helper.positionInfo(child) << ", skipping" << endl;
+ }
+ }
+ }
+ return dataPtr;
+ } /* end process */
+
+
+ XMLSourceCacheParser::XMLSourceCacheParser(istream &is, const string &baseUrl)
+ : zypp::parser::XMLNodeIterator<SourceData_Ptr>(is, baseUrl, "")
+ {
+ fetchNext();
+ }
+
+ } // namespace storage
+} // namespace zypp
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/store/xml/XMLSourceCacheParser.h
+ *
+*/
+
+#ifndef XMLSourceCacheParser_h
+#define XMLSourceCacheParser_h
+
+#include <zypp/target/store/PersistentStorage.h>
+#include <zypp/parser/XMLNodeIterator.h>
+#include <zypp/parser/LibXMLHelper.h>
+#include <list>
+
+typedef zypp::storage::PersistentStorage::SourceData* SourceData_Ptr;
+
+namespace zypp
+{
+namespace storage
+{
+ /*
+ * Use this class as an iterator that produces, one after one,
+ * XMLSourceCacheData_Ptr(s) for the XML group elements.
+ * Here's an example:
+ *
+ * for (XMLSourceCacheParser iter(anIstream, baseUrl),
+ * iter != XMLSourceCacheParser.end(), // or: iter() != 0, or ! iter.atEnd()
+ * ++iter) {
+ * doSomething(*iter)
+ * }
+ *
+ * The iterator owns the pointer (i.e., caller must not delete it)
+ * until the next ++ operator is called. At this time, it will be
+ * destroyed (and a new ENTRYTYPE is created.)
+ *
+ * If the input is fundamentally flawed so that it makes no sense to
+ * continue parsing, XMLNodeIterator will log it and consider the input as finished.
+ * You can query the exit status with errorStatus().
+ */
+
+ class XMLSourceCacheParser : public zypp::parser::XMLNodeIterator<SourceData_Ptr>
+ {
+ public:
+ XMLSourceCacheParser(std::istream &is, const std::string &baseUrl);
+ XMLSourceCacheParser();
+ XMLSourceCacheParser(SourceData_Ptr & entry);
+ virtual ~XMLSourceCacheParser();
+
+ private:
+ virtual bool isInterested(const xmlNodePtr nodePtr);
+ virtual SourceData_Ptr process(const xmlTextReaderPtr reader);
+ void parseSourceList(SourceData_Ptr dataPtr, xmlNodePtr node);
+ zypp::parser::LibXMLHelper _helper;
+ };
+ } // namespace storage
+} // namespace zypp
+
+#endif