From e3d27414040d5a91556dff6408c0c56de635ebea Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 23 Jun 2006 10:15:04 +0000 Subject: [PATCH] Unify SourceInfo class, probably breaks backend, I will fix it after lunch. This class includes a trstate autorefresh, supposed to fix the non working autorefresh. --- zypp/Makefile.am | 1 + zypp/SourceManager.cc | 32 +++++------- zypp/SourceManager.h | 6 +-- zypp/parser/xmlstore/XMLSourceCacheParser.cc | 27 ++++++---- zypp/parser/xmlstore/XMLSourceCacheParser.h | 12 ++--- zypp/source/Makefile.am | 5 +- .../{SourceCreateContext.h => SourceInfo.cc} | 19 +++++--- zypp/source/SourceInfo.h | 57 ++++++++++++++++++++++ zypp/target/store/Backend.h | 4 +- zypp/target/store/PersistentStorage.cc | 4 +- zypp/target/store/PersistentStorage.h | 24 ++------- zypp/target/store/XMLFilesBackend.cc | 10 ++-- zypp/target/store/XMLFilesBackend.h | 4 +- zypp/target/store/serialize.cc | 6 +-- zypp/target/store/serialize.h | 2 +- 15 files changed, 132 insertions(+), 81 deletions(-) rename zypp/source/{SourceCreateContext.h => SourceInfo.cc} (70%) create mode 100644 zypp/source/SourceInfo.h diff --git a/zypp/Makefile.am b/zypp/Makefile.am index 350c715..8167dd0 100644 --- a/zypp/Makefile.am +++ b/zypp/Makefile.am @@ -182,6 +182,7 @@ lib@PACKAGE@_la_LIBADD = thread/lib@PACKAGE@_thread.la \ \ base/lib@PACKAGE@_base.la \ -lboost_filesystem \ + -lsqlite3 \ -lutil # !!! base/lib@PACKAGE@_base.la MUST BE THE LAST zypp lib linked diff --git a/zypp/SourceManager.cc b/zypp/SourceManager.cc index f30ba10..1669762 100644 --- a/zypp/SourceManager.cc +++ b/zypp/SourceManager.cc @@ -292,12 +292,12 @@ namespace zypp for( SourceMap::iterator it = _sources.begin(); it != _sources.end(); it++) { - storage::PersistentStorage::SourceData descr; - + source::SourceInfo descr; + descr.url = it->second.url().asCompleteString(); - descr.enabled = it->second.enabled(); + descr.enabled = it->second.enabled() ? SourceInfo::Enabled : SourceInfo::Disabled; descr.alias = it->second.alias(); - descr.autorefresh = it->second.autorefresh(); + descr.autorefresh = it->second.autorefresh() ? SourceInfo::Enabled : SourceInfo::Disabled; descr.type = it->second.type(); descr.product_dir = it->second.path(); @@ -373,11 +373,11 @@ namespace zypp storage::PersistentStorage store; store.init( root_r ); - std::list new_sources = store.storedSources(); + std::list new_sources = store.storedSources(); MIL << "Found sources: " << new_sources.size() << endl; - for( std::list::iterator it = new_sources.begin(); it != new_sources.end(); ++it) + for( std::list::iterator it = new_sources.begin(); it != new_sources.end(); ++it) { if ( !alias_filter.empty() // check alias filter, if set && (alias_filter != it->alias) ) @@ -471,36 +471,28 @@ namespace zypp storage::PersistentStorage store; store.init( root_r ); - std::list new_sources = store.storedSources(); + std::list new_sources = store.storedSources(); MIL << "Disabling all sources in store at " << root_r << endl; - for( std::list::iterator it = new_sources.begin(); + for( std::list::iterator it = new_sources.begin(); it != new_sources.end(); ++it) { MIL << "Disabling source " << it->alias << endl; - it->enabled = false; + it->enabled = SourceInfo::Disabled; store.storeSource( *it ); } } - SourceManager::SourceInfoList SourceManager::knownSourceInfos(const Pathname &root_r) + source::SourceInfoList SourceManager::knownSourceInfos(const Pathname &root_r) { storage::PersistentStorage store; SourceInfoList result; store.init( root_r ); - std::list sources = store.storedSources(); - + source::SourceInfoList sources = store.storedSources(); MIL << "Found sources: " << sources.size() << endl; - - for( std::list::iterator it = sources.begin(); - it != sources.end(); ++it) - { - SourceInfo info = { it->alias, it->url, it->type, it->autorefresh }; - result.push_back( info ); - } - return result; + return sources; } /****************************************************************** diff --git a/zypp/SourceManager.h b/zypp/SourceManager.h index 1db8dfc..208f9ba 100644 --- a/zypp/SourceManager.h +++ b/zypp/SourceManager.h @@ -22,6 +22,8 @@ #include "zypp/base/Gettext.h" // move with FailedSourcesRestoreException & SourcesAlreadyRestoredException +#include "zypp/source/SourceInfo.h" + #include "zypp/Source.h" #include "zypp/Url.h" #include "zypp/Pathname.h" @@ -143,9 +145,7 @@ namespace zypp * * \throws Exception */ - typedef struct { std::string alias; Url url; std::string type; bool autorefresh; } SourceInfo; - typedef std::list SourceInfoList; - SourceInfoList knownSourceInfos(const Pathname &root_r); + source::SourceInfoList knownSourceInfos(const Pathname &root_r); /** * Store the current state to the given path diff --git a/zypp/parser/xmlstore/XMLSourceCacheParser.cc b/zypp/parser/xmlstore/XMLSourceCacheParser.cc index f729c48..090cd05 100644 --- a/zypp/parser/xmlstore/XMLSourceCacheParser.cc +++ b/zypp/parser/xmlstore/XMLSourceCacheParser.cc @@ -19,10 +19,9 @@ #include #include -#include +#include "XMLSourceCacheParser.h" using namespace std; -using namespace zypp::storage; namespace zypp { namespace parser { @@ -31,8 +30,8 @@ namespace xmlstore { XMLSourceCacheParser::XMLSourceCacheParser() { } - XMLSourceCacheParser::XMLSourceCacheParser(SourceData_Ptr& entry) - : zypp::parser::XMLNodeIterator(entry) + XMLSourceCacheParser::XMLSourceCacheParser(SourceInfo_Ptr &entry) + : zypp::parser::XMLNodeIterator(entry) { } @@ -48,11 +47,11 @@ namespace xmlstore { } // do the actual processing - SourceData_Ptr + SourceInfo_Ptr XMLSourceCacheParser::process(const xmlTextReaderPtr reader) { assert(reader); - SourceData_Ptr dataPtr( new PersistentStorage::SourceData ); + SourceInfo_Ptr dataPtr( new source::SourceInfo ); xmlNodePtr dataNode = xmlTextReaderExpand(reader); assert(dataNode); @@ -63,11 +62,21 @@ namespace xmlstore { string name = _helper.name(child); if (name == "enabled") { - dataPtr->enabled = (_helper.content(child) == "true") ? true : false; + if ( _helper.content(child) == "true" ) + dataPtr->enabled = source::SourceInfo::Enabled; + if ( _helper.content(child) == "false" ) + dataPtr->enabled = source::SourceInfo::Disabled; + else + dataPtr->enabled = source::SourceInfo::NotSet; } else if (name == "auto-refresh") { - dataPtr->autorefresh = (_helper.content(child) == "true") ? true : false; + if ( _helper.content(child) == "true" ) + dataPtr->autorefresh = source::SourceInfo::Enabled; + if ( _helper.content(child) == "false" ) + dataPtr->autorefresh = source::SourceInfo::Disabled; + else + dataPtr->autorefresh = source::SourceInfo::NotSet; } else if (name == "type") { @@ -101,7 +110,7 @@ namespace xmlstore { XMLSourceCacheParser::XMLSourceCacheParser(istream &is, const string &baseUrl) - : zypp::parser::XMLNodeIterator(is, baseUrl, SOURCESCHEMA) + : zypp::parser::XMLNodeIterator(is, baseUrl, SOURCESCHEMA) { fetchNext(); } diff --git a/zypp/parser/xmlstore/XMLSourceCacheParser.h b/zypp/parser/xmlstore/XMLSourceCacheParser.h index b299ec6..37b9b5f 100644 --- a/zypp/parser/xmlstore/XMLSourceCacheParser.h +++ b/zypp/parser/xmlstore/XMLSourceCacheParser.h @@ -13,7 +13,7 @@ #ifndef XMLSourceCacheParser_h #define XMLSourceCacheParser_h -#include +#include #include #include #include @@ -24,7 +24,7 @@ namespace parser { namespace xmlstore { - typedef shared_ptr SourceData_Ptr; + typedef shared_ptr SourceInfo_Ptr; /* * Use this class as an iterator that produces, one after one, @@ -46,18 +46,18 @@ namespace xmlstore * You can query the exit status with errorStatus(). */ - class XMLSourceCacheParser : public zypp::parser::XMLNodeIterator + class XMLSourceCacheParser : public zypp::parser::XMLNodeIterator { public: XMLSourceCacheParser(std::istream &is, const std::string &baseUrl); XMLSourceCacheParser(); - XMLSourceCacheParser(SourceData_Ptr & entry); + XMLSourceCacheParser(SourceInfo_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); + virtual SourceInfo_Ptr process(const xmlTextReaderPtr reader); + void parseSourceList(SourceInfo_Ptr dataPtr, xmlNodePtr node); zypp::parser::LibXMLHelper _helper; }; } // namespace parser diff --git a/zypp/source/Makefile.am b/zypp/source/Makefile.am index 952d039..39a04e7 100644 --- a/zypp/source/Makefile.am +++ b/zypp/source/Makefile.am @@ -15,7 +15,7 @@ sourceinclude_HEADERS = \ Builtin.h \ PackageDelta.h \ MediaSet.h \ - SourceCreateContext.h + SourceInfo.h noinst_LTLIBRARIES = lib@PACKAGE@_source.la @@ -24,7 +24,8 @@ noinst_LTLIBRARIES = lib@PACKAGE@_source.la lib@PACKAGE@_source_la_SOURCES = \ SourceImpl.cc \ PackageDelta.cc \ - MediaSet.cc + MediaSet.cc \ + SourceInfo.cc lib@PACKAGE@_source_la_LIBADD = \ diff --git a/zypp/source/SourceCreateContext.h b/zypp/source/SourceInfo.cc similarity index 70% rename from zypp/source/SourceCreateContext.h rename to zypp/source/SourceInfo.cc index f51244e..d79b53c 100644 --- a/zypp/source/SourceCreateContext.h +++ b/zypp/source/SourceInfo.cc @@ -6,11 +6,12 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ -/** \file zypp/SourceCreateContext.h +/** \file zypp/SourceInfo.cc * */ -#ifndef ZYPP_SourceCreateContext_H -#define ZYPP_SourceCreateContext_H + +#include +#include "zypp/source/SourceInfo.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -18,13 +19,17 @@ namespace zypp namespace source { - struct SourceCreateContext + std::ostream & operator<<( std::ostream & str, const SourceInfo::EnabledState & obj ) { - - } + if ( obj == SourceInfo::Enabled ) + return str << std::string("true"); + if ( obj == SourceInfo::Disabled ) + return str << std::string("false"); + else + return str << std::string("not-set"); + } } ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// -#endif // ZYPP_SourceCreateContext_H diff --git a/zypp/source/SourceInfo.h b/zypp/source/SourceInfo.h new file mode 100644 index 0000000..f89b314 --- /dev/null +++ b/zypp/source/SourceInfo.h @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/SourceInfo.h + * +*/ +#ifndef ZYPP_SourceInfo_H +#define ZYPP_SourceInfo_H + +#include + +#include "zypp/Pathname.h" +#include "zypp/Url.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +namespace source +{ + + struct SourceInfo + { + enum EnabledState { + Enabled, + Disabled, + NotSet + }; + + SourceInfo() : + enabled (NotSet), + autorefresh(NotSet) + { + + }; + + EnabledState enabled; + EnabledState autorefresh; + Pathname product_dir; + std::string type; + Url url; + Pathname cache_dir; + std::string alias; + }; + + std::ostream & operator<<( std::ostream & str, const SourceInfo::EnabledState & obj ); + typedef std::list SourceInfoList; + +} + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SourceInfo_H diff --git a/zypp/target/store/Backend.h b/zypp/target/store/Backend.h index 181bfa2..adf8a8f 100644 --- a/zypp/target/store/Backend.h +++ b/zypp/target/store/Backend.h @@ -105,11 +105,11 @@ public: /** * Query for installed Sources */ - virtual std::list storedSources() const = 0; + virtual source::SourceInfoList storedSources() const = 0; /** * Query for installed Sources */ - virtual void storeSource(const PersistentStorage::SourceData &data) = 0; + virtual void storeSource(const source::SourceInfo &data) = 0; /** * Query for installed Sources */ diff --git a/zypp/target/store/PersistentStorage.cc b/zypp/target/store/PersistentStorage.cc index 3c67482..c0221f6 100644 --- a/zypp/target/store/PersistentStorage.cc +++ b/zypp/target/store/PersistentStorage.cc @@ -169,14 +169,14 @@ PersistentStorage::hasFlag( const std::string &key, const std::string &flag ) co // SOURCES API //////////////////////////////////////////////////////// -std::list +source::SourceInfoList PersistentStorage::storedSources() const { return d->backend->storedSources(); } void -PersistentStorage::storeSource(const PersistentStorage::SourceData &data) +PersistentStorage::storeSource(const source::SourceInfo &data) { d->backend->storeSource(data); } diff --git a/zypp/target/store/PersistentStorage.h b/zypp/target/store/PersistentStorage.h index b39ebf6..95789a9 100644 --- a/zypp/target/store/PersistentStorage.h +++ b/zypp/target/store/PersistentStorage.h @@ -21,6 +21,9 @@ #include #include #include +#include + +using namespace zypp::source; /////////////////////////////////////////////////////////////////// namespace zypp @@ -45,23 +48,6 @@ namespace zypp ~PersistentStorage(); void doTest(); - struct SourceData - { - SourceData() - { - enabled = true; - autorefresh = false; - }; - - bool enabled; - bool autorefresh; - Pathname product_dir; - std::string type; - Url url; - Pathname cache_dir; - std::string alias; - }; - public: /** * Initializes the Storage when the system is located in some @@ -136,11 +122,11 @@ namespace zypp /** * Query for installed Sources */ - std::list storedSources() const; + std::list storedSources() const; /** * Add a new installed source */ - void storeSource(const SourceData &data); + void storeSource(const SourceInfo &data); /** * Delete an installed source */ diff --git a/zypp/target/store/XMLFilesBackend.cc b/zypp/target/store/XMLFilesBackend.cc index fc2a030..ed435eb 100644 --- a/zypp/target/store/XMLFilesBackend.cc +++ b/zypp/target/store/XMLFilesBackend.cc @@ -1202,18 +1202,18 @@ std::ostream & operator<<( std::ostream & str, const XMLFilesBackend & obj ) // SOURCES API //////////////////////////////////////////////////////// -std::list +source::SourceInfoList XMLFilesBackend::storedSources() const { path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("sources"); - std::list sources; + source::SourceInfoList sources; DBG << "Reading source cache in " << source_p.string() << std::endl; directory_iterator end_iter; // return empty list if the dir does not exist if ( !exists( source_p ) ) { ERR << "path " << source_p.string() << " does not exists. Required to read source cache " << std::endl; - return std::list(); + return source::SourceInfoList(); } for ( directory_iterator dir_itr( source_p ); dir_itr != end_iter; ++dir_itr ) @@ -1224,7 +1224,7 @@ XMLFilesBackend::storedSources() const std::ifstream anIstream(full_path.c_str()); zypp::parser::xmlstore::XMLSourceCacheParser iter(anIstream, ""); for (; ! iter.atEnd(); ++iter) { - PersistentStorage::SourceData data = **iter; + source::SourceInfo data = **iter; sources.push_back(data); } } @@ -1234,7 +1234,7 @@ XMLFilesBackend::storedSources() const } void -XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) +XMLFilesBackend::storeSource(const source::SourceInfo &data) { // serialize and save a file std::string xml = toXML(data); diff --git a/zypp/target/store/XMLFilesBackend.h b/zypp/target/store/XMLFilesBackend.h index ecfa93f..14146e4 100644 --- a/zypp/target/store/XMLFilesBackend.h +++ b/zypp/target/store/XMLFilesBackend.h @@ -123,11 +123,11 @@ public: /** * Query for installed Sources */ - virtual std::list storedSources() const; + virtual source::SourceInfoList storedSources() const; /** * Query for installed Sources */ - virtual void storeSource(const PersistentStorage::SourceData &data); + virtual void storeSource(const source::SourceInfo &data); /** * Query for installed Sources */ diff --git a/zypp/target/store/serialize.cc b/zypp/target/store/serialize.cc index f60aa9f..18aa051 100644 --- a/zypp/target/store/serialize.cc +++ b/zypp/target/store/serialize.cc @@ -431,13 +431,13 @@ std::string toXML( const Patch::constPtr &obj ) } template<> -std::string toXML( const PersistentStorage::SourceData &obj ) +std::string toXML( const source::SourceInfo &obj ) { stringstream out; out << "" << std::endl; out << "" << std::endl; - out << " " << (obj.enabled ? "true" : "false" ) << "" << std::endl; - out << " " << ( obj.autorefresh ? "true" : "false" ) << "" << std::endl; + out << " " << obj.enabled << "" << std::endl; + out << " " << obj.autorefresh << "" << std::endl; out << " " << obj.product_dir << "" << std::endl; out << " " << obj.cache_dir << "" << std::endl; out << " " << xml_escape(obj.type) << "" << std::endl; diff --git a/zypp/target/store/serialize.h b/zypp/target/store/serialize.h index b945316..909f85b 100644 --- a/zypp/target/store/serialize.h +++ b/zypp/target/store/serialize.h @@ -117,7 +117,7 @@ template<> std::string toXML( const Language::constPtr &obj ); template<> -std::string toXML( const PersistentStorage::SourceData &obj ); +std::string toXML( const source::SourceInfo &obj ); ///////////////////////////////////////////////////////////////// } // namespace storage -- 2.7.4