From 4e2e4ea85da4bb3791969dda80aadf30af6e04f0 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 26 Jun 2006 15:16:33 +0000 Subject: [PATCH] - fix refresh in trunk, aka #186115 --- zypp/SourceFactory.cc | 39 ++++++++++++++++------------ zypp/SourceFactory.h | 7 +++-- zypp/SourceManager.cc | 7 +++-- zypp/parser/xmlstore/XMLSourceCacheParser.cc | 12 ++++++--- zypp/source/SourceImpl.cc | 9 +++---- zypp/source/SourceImpl.h | 8 +++--- zypp/source/sqlite-source/SqliteSources.cc | 4 +-- zypp/source/susetags/SuseTagsImpl.cc | 3 +++ zypp/source/yum/YUMSourceImpl.cc | 2 ++ zypp/target/store/serialize.cc | 14 ++++++++-- 10 files changed, 66 insertions(+), 39 deletions(-) diff --git a/zypp/SourceFactory.cc b/zypp/SourceFactory.cc index 19f1bff..0900132 100644 --- a/zypp/SourceFactory.cc +++ b/zypp/SourceFactory.cc @@ -43,10 +43,11 @@ namespace zypp static Source_Ref::Impl_Ptr createSourceImpl( const media::MediaId & media_r, const Pathname & path_r, const std::string & alias_r, - const Pathname & cache_dir_r) + const Pathname & cache_dir_r, + bool auto_refresh ) { Source_Ref::Impl_Ptr impl( new _SourceImpl ); - impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, false ); + impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, false, auto_refresh ); return impl; } @@ -57,10 +58,11 @@ namespace zypp static Source_Ref::Impl_Ptr createBaseSourceImpl( const media::MediaId & media_r, const Pathname & path_r, const std::string & alias_r, - const Pathname & cache_dir_r) + const Pathname & cache_dir_r, + bool auto_refresh ) { Source_Ref::Impl_Ptr impl( new _SourceImpl ); - impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, true ); + impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, true, auto_refresh); return impl; } @@ -128,7 +130,7 @@ namespace zypp 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 ) + Source_Ref SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source ) { if (! url_r.isValid()) ZYPP_THROW( Exception("Empty URL passed to SourceFactory") ); @@ -153,12 +155,13 @@ namespace zypp MIL << "Initializing from cache" << endl; } + bool auto_refresh = media::MediaAccess::canBeVolatile( url_r ); try { MIL << "Trying the YUM source" << endl; Source_Ref::Impl_Ptr impl( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); MIL << "Found the YUM source" << endl; report->endProbe (url_r); @@ -174,8 +177,8 @@ namespace zypp { MIL << "Trying the SUSE tags source" << endl; Source_Ref::Impl_Ptr impl( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); MIL << "Found the SUSE tags source" << endl; report->endProbe (url_r); @@ -216,7 +219,7 @@ namespace zypp return Source_Ref(); // not reached!! } - Source_Ref SourceFactory::createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, const bool base_source ) + Source_Ref SourceFactory::createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh ) { if (! url_r.isValid()) ZYPP_THROW( Exception("Empty URL passed to SourceFactory") ); @@ -241,6 +244,10 @@ namespace zypp MIL << "Initializing from cache" << endl; } + // Sane default for unknown autorefresh + if ( auto_refresh == indeterminate ) + auto_refresh = media::MediaAccess::canBeVolatile( url_r ); + try { @@ -249,20 +256,20 @@ namespace zypp if( type == yum::YUMSourceImpl::typeString() ) { MIL << "Trying the YUM source" << endl; impl = Source_Ref::Impl_Ptr( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); MIL << "Found the YUM source" << endl; } else if ( type == susetags::SuseTagsImpl::typeString() ) { MIL << "Trying the SUSE tags source" << endl; impl = Source_Ref::Impl_Ptr( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); MIL << "Found the SUSE tags source" << endl; } else if ( type == PlaindirImpl::typeString() ) { MIL << "Trying the Plaindir source" << endl; impl = Source_Ref::Impl_Ptr( base_source - ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r) - : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r) ); + ? Impl::createBaseSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) + : Impl::createSourceImpl(id, path_r, alias_r, cache_dir_r, auto_refresh) ); MIL << "Found the Plaindir source" << endl; } else { ZYPP_THROW( Exception ("Cannot create source of unknown type '" + type + "'")); diff --git a/zypp/SourceFactory.h b/zypp/SourceFactory.h index c09f236..4a57067 100644 --- a/zypp/SourceFactory.h +++ b/zypp/SourceFactory.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "zypp/base/PtrTypes.h" @@ -23,6 +24,8 @@ #include "zypp/Url.h" #include "zypp/Pathname.h" +using namespace boost; + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -59,12 +62,12 @@ namespace zypp /** Construct source. * \throw EXCEPTION on fail */ - Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", const bool base_source = false ); + Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", bool base_source = false ); /** Construct source of a given type. * \throw EXCEPTION on fail */ - Source_Ref createFrom( const std::string & type, const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", const bool base_source = false ); + Source_Ref createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh ); private: /** Implementation */ diff --git a/zypp/SourceManager.cc b/zypp/SourceManager.cc index 511ffa0..668004b 100644 --- a/zypp/SourceManager.cc +++ b/zypp/SourceManager.cc @@ -392,12 +392,12 @@ namespace zypp } // Note: Url(it->url).asString() to hide password in logs - MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "]" << endl; + MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl; SourceId id = 0; try { - id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir()) ); + id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), false, it->autorefresh()) ); } catch (const Exception &expt ) { @@ -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->path(), it->alias(), it->cacheDir()) ); + id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir(), false ) ); // This worked ... update it->url ? //it->url = url2.asCompleteString(); @@ -453,7 +453,6 @@ namespace zypp DBG << "disable source" << endl; src.disable(); } - src.setAutorefresh ( it->autorefresh() ); } if( !report.empty() ) diff --git a/zypp/parser/xmlstore/XMLSourceCacheParser.cc b/zypp/parser/xmlstore/XMLSourceCacheParser.cc index dd4caed..fb20230 100644 --- a/zypp/parser/xmlstore/XMLSourceCacheParser.cc +++ b/zypp/parser/xmlstore/XMLSourceCacheParser.cc @@ -62,17 +62,21 @@ namespace xmlstore { string name = _helper.name(child); if (name == "enabled") { - if ( _helper.content(child) == "true" ) + if ( (_helper.content(child) == "true") || (_helper.content(child) == "1") ) dataPtr->setEnabled(true); - else + else if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") ) dataPtr->setEnabled(false); + else + dataPtr->setEnabled(indeterminate); } else if (name == "auto-refresh") { - if ( _helper.content(child) == "true" ) + if ( (_helper.content(child) == "true") || (_helper.content(child) == "1") ) dataPtr->setAutorefresh(true); - else + if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") ) dataPtr->setAutorefresh(false); + else + dataPtr->setAutorefresh(indeterminate); } else if (name == "type") { diff --git a/zypp/source/SourceImpl.cc b/zypp/source/SourceImpl.cc index 3998beb..b762d94 100644 --- a/zypp/source/SourceImpl.cc +++ b/zypp/source/SourceImpl.cc @@ -127,7 +127,8 @@ namespace zypp const Pathname & path_r, const std::string & alias_r, const Pathname cache_dir_r, - const bool base_source) + bool base_source, + bool auto_refresh ) { _media_set = new MediaSet( selfSourceRef() ); _url = media_mgr.url( media_r ); @@ -137,10 +138,8 @@ namespace zypp _cache_dir = cache_dir_r; _subscribed = true; _base_source = base_source; - - // for sources which are neither CD nor DVD we enable autorefresh by default - _autorefresh = media::MediaAccess::canBeVolatile( _url ); - + _autorefresh = auto_refresh; + try { factoryInit(); diff --git a/zypp/source/SourceImpl.h b/zypp/source/SourceImpl.h index 5e8a742..501465e 100644 --- a/zypp/source/SourceImpl.h +++ b/zypp/source/SourceImpl.h @@ -74,10 +74,10 @@ namespace zypp * \throw EXCEPTION on fail */ void factoryCtor( const media::MediaId & media_r, - const Pathname & path_r = "/", - const std::string & alias_r = "", - const Pathname cache_dir_r = "", - const bool base_source = false); + const Pathname & path_r, + const std::string & alias_r, + const Pathname cache_dir_r, + bool base_source, bool auto_refresh); /** SourceImpl MediaVerifier. */ class Verifier; diff --git a/zypp/source/sqlite-source/SqliteSources.cc b/zypp/source/sqlite-source/SqliteSources.cc index 9f65347..13cbfbc 100644 --- a/zypp/source/sqlite-source/SqliteSources.cc +++ b/zypp/source/sqlite-source/SqliteSources.cc @@ -71,7 +71,7 @@ SqliteSources::createDummy( const Url & url, const string & catalog ) try { SqliteSourceImpl *impl = new SqliteSourceImpl (); - impl->factoryCtor( mediaid, Pathname(), catalog ); + impl->factoryCtor( mediaid, Pathname(), catalog, "", false, false ); impl->setId( catalog ); impl->setZmdName( catalog ); impl->setZmdDescription ( catalog ); @@ -212,7 +212,7 @@ SqliteSources::sources( bool zypp_restore, bool refresh ) try { SqliteSourceImpl *impl = new SqliteSourceImpl (); - impl->factoryCtor( mediaid, Pathname(), alias ); + impl->factoryCtor( mediaid, Pathname(), alias, "", false, false ); impl->setId( id ); impl->setZmdName( name ); impl->setZmdDescription ( desc ); diff --git a/zypp/source/susetags/SuseTagsImpl.cc b/zypp/source/susetags/SuseTagsImpl.cc index 033ffd4..b2f10a8 100644 --- a/zypp/source/susetags/SuseTagsImpl.cc +++ b/zypp/source/susetags/SuseTagsImpl.cc @@ -405,6 +405,9 @@ namespace zypp // in the media. readMediaFile(mediaFile()); readContentFile(contentFile()); + + if ( autorefresh() ) + storeMetadata(_cache_dir); } else { diff --git a/zypp/source/yum/YUMSourceImpl.cc b/zypp/source/yum/YUMSourceImpl.cc index aa0037a..15a7c7e 100644 --- a/zypp/source/yum/YUMSourceImpl.cc +++ b/zypp/source/yum/YUMSourceImpl.cc @@ -202,6 +202,8 @@ namespace zypp if ( cache ) { DBG << "Cached metadata found in [" << _cache_dir << "]." << endl; + if ( autorefresh() ) + storeMetadata(_cache_dir); } else { diff --git a/zypp/target/store/serialize.cc b/zypp/target/store/serialize.cc index 9be727a..3ebf376 100644 --- a/zypp/target/store/serialize.cc +++ b/zypp/target/store/serialize.cc @@ -35,13 +35,13 @@ namespace zypp namespace storage { ///////////////////////////////////////////////////////////////// -std::string xml_escape( const std::string &text ) +static std::string xml_escape( const std::string &text ) { iobind::parser::xml_escape_parser parser; return parser.escape(text); } -std::string xml_tag_enclose( const std::string &text, const std::string &tag, bool escape = false ) +static std::string xml_tag_enclose( const std::string &text, const std::string &tag, bool escape = false ) { std::string result; result += "<" + tag + ">"; @@ -55,6 +55,16 @@ std::string xml_tag_enclose( const std::string &text, const std::string &tag, bo return result; } +static std::ostream & operator<<( std::ostream & str, const tribool obj ) +{ + if (obj) + return str << "true"; + else if (!obj) + return str << "false"; + else + return str << "indeterminate"; +} + /** * helper function that builds * text -- 2.7.4