From: Duncan Mac-Vicar P Date: Mon, 26 Jun 2006 09:25:28 +0000 (+0000) Subject: - adapt everything to SourceInfo with accesors and tribool status X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~601 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9341f7db04cfc4974208bbe1799eaeb8dba082b;p=platform%2Fupstream%2Flibzypp.git - adapt everything to SourceInfo with accesors and tribool status for autorefresh and enabled --- diff --git a/testsuite/target/tests/import_old_sources_test.cc b/testsuite/target/tests/import_old_sources_test.cc index d626dd8..a3d1ce0 100644 --- a/testsuite/target/tests/import_old_sources_test.cc +++ b/testsuite/target/tests/import_old_sources_test.cc @@ -15,6 +15,7 @@ #include "zypp/base/Exception.h" /////////////////////////////////////////////////////////////////// +#include "zypp/source/SourceInfo.h" #include "zypp/target/store/PersistentStorage.h" #include "zypp/target/store/XMLFilesBackend.h" #include "zypp/parser/tagfile/TagFileParser.h" @@ -33,9 +34,6 @@ #include "zypp/target/store/serialize.h" -#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp -#include "boost/filesystem/fstream.hpp" // ditto - using namespace zypp::detail; using namespace std; using namespace zypp; @@ -65,7 +63,7 @@ using namespace boost::filesystem; */ struct OldPMSourceParser : public parser::tagfile::TagFileParser { - PersistentStorage::SourceData result; + source::SourceInfo result; virtual void beginParse() { @@ -74,18 +72,18 @@ struct OldPMSourceParser : public parser::tagfile::TagFileParser virtual void consume( const SingleTag & stag_r ) { if ( stag_r.name == "Type" ) - result.type = stag_r.value; + result.setType(stag_r.value); if ( stag_r.name == "URL" ) { - result.url = stag_r.value; - result.alias = stag_r.value; + result.setUrl(stag_r.value); + result.setAlias(stag_r.value); } if ( stag_r.name == "ProductDir" ) - result.product_dir = stag_r.value; + result.setPath(stag_r.value); if ( stag_r.name == "Default_activate" ) - result.enabled = (stag_r.value == "1") ? true : false; + result.setEnabled( (stag_r.value == "1") ? true : false ); if ( stag_r.name == "Default_refresh" ) - result.autorefresh = (stag_r.value == "1") ? true : false; + result.setAutorefresh( (stag_r.value == "1") ? true : false ); } /* Consume MulitTag data. */ diff --git a/testsuite/target/tests/storagetargettest.cc b/testsuite/target/tests/storagetargettest.cc index 6f6f3db..76bad4d 100644 --- a/testsuite/target/tests/storagetargettest.cc +++ b/testsuite/target/tests/storagetargettest.cc @@ -14,6 +14,7 @@ #include "zypp/base/Exception.h" /////////////////////////////////////////////////////////////////// +#include "zypp/source/SourceInfo.h" #include "zypp/target/store/PersistentStorage.h" #include "zypp/target/store/XMLFilesBackend.h" @@ -36,9 +37,6 @@ #include "zypp/target/store/serialize.h" -#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp -#include "boost/filesystem/fstream.hpp" // ditto - #include "Benchmark.h" using namespace zypp::detail; @@ -106,8 +104,8 @@ struct StorageTargetTest if (zyppvar == "/var") ZYPP_THROW(Exception("I refuse to delete /var")); - filesystem::recursive_rmdir( zyppvar ); - filesystem::recursive_rmdir( zyppcache ); +// filesystem::recursive_rmdir( zyppvar ); +// filesystem::recursive_rmdir( zyppcache ); _store.clear(); } @@ -192,10 +190,10 @@ struct StorageTargetTest void storeKnownSources() { INT << "===[SOURCES]==========================================" << endl; - PersistentStorage::SourceData data; - data.url = _source.url().asString(); - data.type = _source.type(); - data.alias = _source.alias(); + source::SourceInfo data; + data.setUrl(_source.url()); + data.setType(_source.type()); + data.setAlias(_source.alias()); _backend->storeSource(data); MIL << "Wrote 1 source" << std::endl; @@ -247,7 +245,7 @@ struct StorageTargetTest clean(); unpackDatabase("db.tar.gz"); initStorageBackend(); - std::list sources = _backend->storedSources(); + source::SourceInfoList sources = _backend->storedSources(); MIL << "Read " << sources.size() << " sources" << std::endl; if ( sources.size() != 2 ) ZYPP_THROW(Exception("Known Sources read FAILED")); diff --git a/zypp/SourceFactory.cc b/zypp/SourceFactory.cc index e87665b..19f1bff 100644 --- a/zypp/SourceFactory.cc +++ b/zypp/SourceFactory.cc @@ -123,6 +123,11 @@ namespace zypp media_mgr.release(id); } + Source_Ref SourceFactory::createFrom( const source::SourceInfo &context ) + { + return Source_Ref::noSource; + } + Source_Ref SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, const bool base_source ) { if (! url_r.isValid()) diff --git a/zypp/SourceFactory.h b/zypp/SourceFactory.h index 50d792e..c09f236 100644 --- a/zypp/SourceFactory.h +++ b/zypp/SourceFactory.h @@ -19,6 +19,7 @@ #include "zypp/base/PtrTypes.h" #include "zypp/Source.h" +#include "zypp/source/SourceInfo.h" #include "zypp/Url.h" #include "zypp/Pathname.h" @@ -45,6 +46,11 @@ namespace zypp ~SourceFactory(); public: + /** Construct source. + * \throw EXCEPTION on fail + */ + Source_Ref createFrom( const source::SourceInfo & context ); + /** Construct source from an implementation. * Returns Source_Ref::noSource on NULL \a impl_r. */ diff --git a/zypp/SourceManager.cc b/zypp/SourceManager.cc index 1669762..511ffa0 100644 --- a/zypp/SourceManager.cc +++ b/zypp/SourceManager.cc @@ -294,33 +294,33 @@ namespace zypp { source::SourceInfo descr; - descr.url = it->second.url().asCompleteString(); - descr.enabled = it->second.enabled() ? SourceInfo::Enabled : SourceInfo::Disabled; - descr.alias = it->second.alias(); - descr.autorefresh = it->second.autorefresh() ? SourceInfo::Enabled : SourceInfo::Disabled; - descr.type = it->second.type(); - descr.product_dir = it->second.path(); + descr.setUrl(it->second.url()); + descr.setEnabled( it->second.enabled() ); + descr.setAlias( it->second.alias() ); + descr.setAutorefresh( it->second.autorefresh() ); + descr.setType( it->second.type() ); + descr.setPath( it->second.path() ); - descr.cache_dir = it->second.cacheDir(); + descr.setCacheDir( it->second.cacheDir() ); - if( metadata_cache && descr.cache_dir.empty() ) + if( metadata_cache && descr.cacheDir().empty() ) { - if( descr.cache_dir.empty() ) + if( descr.cacheDir().empty() ) { filesystem::TmpDir newCache( root_r / ZYPP_METADATA_PREFIX, "Source." ); - descr.cache_dir = ZYPP_METADATA_PREFIX + newCache.path().basename(); + descr.setCacheDir( ZYPP_METADATA_PREFIX + newCache.path().basename() ); } - filesystem::assert_dir ( root_r.asString() + descr.cache_dir ); + filesystem::assert_dir ( root_r.asString() + descr.cacheDir() ); - MIL << "Storing metadata to (" << root_r.asString() << ")/" << descr.cache_dir << endl; + MIL << "Storing metadata to (" << root_r.asString() << ")/" << descr.cacheDir() << endl; try { - it->second.storeMetadata( root_r.asString() + descr.cache_dir ); + it->second.storeMetadata( root_r.asString() + descr.cacheDir() ); } catch(const Exception &excp) { WAR << "Creating local metadata cache failed, not using cache" << endl; - descr.cache_dir = ""; + descr.setCacheDir(""); } } @@ -380,35 +380,35 @@ namespace zypp 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) ) + && (alias_filter != it->alias()) ) { continue; } if ( !url_filter.empty() // check url filter, if set - && (url_filter != it->url.asString()) ) + && (url_filter != it->url().asString()) ) { continue; } // Note: Url(it->url).asString() to hide password in logs - MIL << "Restoring source: url:[" << Url(it->url).asString() << "] product_dir:[" << it->product_dir << "] alias:[" << it->alias << "] cache_dir:[" << it->cache_dir << "]" << endl; + MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "]" << endl; SourceId id = 0; try { - id = addSource( SourceFactory().createFrom(it->type, it->url, it->product_dir, it->alias, it->cache_dir) ); + id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir()) ); } catch (const Exception &expt ) { // Note: Url(it->url).asString() to hide password in logs - ERR << "Unable to restore source from " << Url(it->url).asString() + ERR << "Unable to restore source from " << it->url().asString() << endl; id = 0; Url url2; try { - url2 = it->url; + url2 = it->url(); std::string scheme( url2.getScheme()); if( (scheme == "cd" || scheme == "dvd") && @@ -419,7 +419,7 @@ namespace zypp DBG << "CD/DVD devices changed - try again without a devices list" << std::endl; - id = addSource( SourceFactory().createFrom(url2, it->product_dir, it->alias, it->cache_dir) ); + id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir()) ); // This worked ... update it->url ? //it->url = url2.asCompleteString(); @@ -436,7 +436,7 @@ namespace zypp if( id == 0) { - report.append( it->url.asString() + it->product_dir.asString(), it->alias, expt ); + report.append( it->url().asString() + it->path().asString(), it->alias(), expt ); continue; } } @@ -445,7 +445,7 @@ namespace zypp // should not throw, we've just created the source Source_Ref src = findSource( id ); - if ( it->enabled ) { + if ( it->enabled() ) { DBG << "enable source" << endl; src.enable(); } @@ -453,7 +453,7 @@ namespace zypp DBG << "disable source" << endl; src.disable(); } - src.setAutorefresh ( it->autorefresh ); + src.setAutorefresh ( it->autorefresh() ); } if( !report.empty() ) @@ -478,8 +478,8 @@ namespace zypp for( std::list::iterator it = new_sources.begin(); it != new_sources.end(); ++it) { - MIL << "Disabling source " << it->alias << endl; - it->enabled = SourceInfo::Disabled; + MIL << "Disabling source " << it->alias() << endl; + it->setEnabled(false); store.storeSource( *it ); } } diff --git a/zypp/parser/xmlstore/XMLSourceCacheParser.cc b/zypp/parser/xmlstore/XMLSourceCacheParser.cc index 090cd05..dd4caed 100644 --- a/zypp/parser/xmlstore/XMLSourceCacheParser.cc +++ b/zypp/parser/xmlstore/XMLSourceCacheParser.cc @@ -63,40 +63,36 @@ namespace xmlstore { if (name == "enabled") { if ( _helper.content(child) == "true" ) - dataPtr->enabled = source::SourceInfo::Enabled; - if ( _helper.content(child) == "false" ) - dataPtr->enabled = source::SourceInfo::Disabled; + dataPtr->setEnabled(true); else - dataPtr->enabled = source::SourceInfo::NotSet; + dataPtr->setEnabled(false); } else if (name == "auto-refresh") { if ( _helper.content(child) == "true" ) - dataPtr->autorefresh = source::SourceInfo::Enabled; - if ( _helper.content(child) == "false" ) - dataPtr->autorefresh = source::SourceInfo::Disabled; + dataPtr->setAutorefresh(true); else - dataPtr->autorefresh = source::SourceInfo::NotSet; + dataPtr->setAutorefresh(false); } else if (name == "type") { - dataPtr->type = _helper.content(child); + dataPtr->setType(_helper.content(child)); } else if (name == "product-dir") { - dataPtr->product_dir = _helper.content(child); + dataPtr->setPath(_helper.content(child)); } else if (name == "cache-dir") { - dataPtr->cache_dir = _helper.content(child); + dataPtr->setCacheDir(_helper.content(child)); } else if (name == "alias") { - dataPtr->alias = _helper.content(child); + dataPtr->setAlias(_helper.content(child)); } else if (name == "url") { - dataPtr->url = _helper.content(child); + dataPtr->setUrl(_helper.content(child)); } else { diff --git a/zypp/source/SourceInfo.cc b/zypp/source/SourceInfo.cc index d79b53c..5074fc4 100644 --- a/zypp/source/SourceInfo.cc +++ b/zypp/source/SourceInfo.cc @@ -19,15 +19,7 @@ namespace zypp namespace source { - 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"); - } + } ///////////////////////////////////////////////////////////////// diff --git a/zypp/source/SourceInfo.h b/zypp/source/SourceInfo.h index f89b314..942ab61 100644 --- a/zypp/source/SourceInfo.h +++ b/zypp/source/SourceInfo.h @@ -14,42 +14,115 @@ #include +#include #include "zypp/Pathname.h" #include "zypp/Url.h" +using namespace boost; + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// namespace source { - struct SourceInfo + class SourceInfo { - enum EnabledState { - Enabled, - Disabled, - NotSet - }; - + public: + SourceInfo() : - enabled (NotSet), - autorefresh(NotSet) + _enabled (indeterminate), + _autorefresh(indeterminate) { - }; - - EnabledState enabled; - EnabledState autorefresh; - Pathname product_dir; - std::string type; - Url url; - Pathname cache_dir; - std::string alias; + } + + SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", tribool autorefresh = indeterminate) + : _enabled (true), + _autorefresh(autorefresh), + _url(url), + _cache_dir(cache_dir), + _path(path), + _alias(alias) + { + + } + + SourceInfo & setEnabled( bool enabled ) + { + _enabled = enabled; + return *this; + } + + SourceInfo & setAutorefresh( bool autorefresh ) + { + _autorefresh = autorefresh; + return *this; + } + + SourceInfo & setUrl( const Url &url ) + { + _url = url; + return *this; + } + + SourceInfo & setPath( const Pathname &p ) + { + _path = p; + return *this; + } + + SourceInfo & setAlias( const std::string &alias ) + { + _alias = alias; + return *this; + } + + SourceInfo & setType( const std::string &t ) + { + _type = t; + return *this; + } + + SourceInfo & setCacheDir( const Pathname &p ) + { + _cache_dir = p; + return *this; + } + + tribool enabled() const + { return _enabled; } + + tribool autorefresh() const + { return _enabled; } + + Pathname cacheDir() const + { return _cache_dir; } + + Pathname path() const + { return _path; } + + std::string alias() const + { return _alias; } + + std::string type() const + { return _type; } + + Url url() const + { return _url; } + + private: + + tribool _enabled; + tribool _autorefresh; + std::string _type; + Url _url; + Pathname _cache_dir; + Pathname _path; + std::string _alias; }; - std::ostream & operator<<( std::ostream & str, const SourceInfo::EnabledState & obj ); typedef std::list SourceInfoList; - } ///////////////////////////////////////////////////////////////// } // namespace zypp diff --git a/zypp/target/store/XMLFilesBackend.cc b/zypp/target/store/XMLFilesBackend.cc index ed435eb..58aa73d 100644 --- a/zypp/target/store/XMLFilesBackend.cc +++ b/zypp/target/store/XMLFilesBackend.cc @@ -1241,7 +1241,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data) path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("sources"); // generate a filename - if (data.alias.size() == 0) + if (data.alias().size() == 0) { ZYPP_THROW(Exception("Cant save source with empty alias")); } @@ -1251,7 +1251,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data) //DBG << filename << std::endl; try { - std::stringstream message_stream(data.alias); + std::stringstream message_stream(data.alias()); std::string full_path = (source_p / Digest::digest("MD5", message_stream)).string(); file.open(full_path.c_str()); @@ -1260,7 +1260,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data) } catch ( std::exception &e ) { - ERR << "Error saving source " << data.alias << " in the cache" << std::endl; + ERR << "Error saving source " << data.alias() << " in the cache" << std::endl; ZYPP_THROW(Exception(e.what())); } updateTimestamp(); diff --git a/zypp/target/store/serialize.cc b/zypp/target/store/serialize.cc index 18aa051..9be727a 100644 --- a/zypp/target/store/serialize.cc +++ b/zypp/target/store/serialize.cc @@ -436,13 +436,13 @@ std::string toXML( const source::SourceInfo &obj ) stringstream out; out << "" << std::endl; out << "" << 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; - out << " " << xml_escape(obj.url.asCompleteString()) << "" << std::endl; - out << " " << xml_escape(obj.alias) << "" << std::endl; + out << " " << obj.enabled() << "" << std::endl; + out << " " << obj.autorefresh() << "" << std::endl; + out << " " << obj.path() << "" << std::endl; + out << " " << obj.cacheDir() << "" << std::endl; + out << " " << xml_escape(obj.type()) << "" << std::endl; + out << " " << xml_escape(obj.url().asCompleteString()) << "" << std::endl; + out << " " << xml_escape(obj.alias()) << "" << std::endl; out << "" << std::endl; return out.str(); }