From 0a1b69726016aa9c45845c125878da5a9de1c55f Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 9 Jun 2006 16:06:28 +0000 Subject: [PATCH] fix logic here, we want to restore only the source with alias A not till we find alias A --- zypp/SourceManager.cc | 135 +++++++++++++++++++++++++------------------------- zypp/SourceManager.h | 2 +- 2 files changed, 68 insertions(+), 69 deletions(-) diff --git a/zypp/SourceManager.cc b/zypp/SourceManager.cc index f7af063..28f2443 100644 --- a/zypp/SourceManager.cc +++ b/zypp/SourceManager.cc @@ -321,7 +321,7 @@ namespace zypp /** \todo Broken design: either use return value or Exception to * indicate errors, not both. */ - bool SourceManager::restore( Pathname root_r, bool use_caches, std::string alias_filter ) + bool SourceManager::restore( Pathname root_r, bool use_caches, const std::string &alias_filter ) { MIL << "SourceManager restore '" << root_r << ( use_caches ? "' (use_caches)" : "'" ) << " ..." << endl; @@ -342,73 +342,72 @@ namespace zypp for( std::list::iterator it = new_sources.begin(); it != new_sources.end(); ++it) { - // 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; - - SourceId id = 0; - - try { - id = addSource( SourceFactory().createFrom(it->type, it->url, it->product_dir, it->alias, it->cache_dir) ); - } - catch (const Exception &expt ) - { - // Note: Url(it->url).asString() to hide password in logs - ERR << "Unable to restore source from " << Url(it->url).asString() - << endl; - - id = 0; - Url url2; - try { - url2 = it->url; - std::string scheme( url2.getScheme()); - - if( (scheme == "cd" || scheme == "dvd") && - !url2.getQueryParam("devices").empty()) - { - url2.setQueryParam("devices", ""); - - 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) ); - - // This worked ... update it->url ? - //it->url = url2.asCompleteString(); - } - } - catch (const Exception &e2) - { - // Note: Url(it->url).asString() to hide password in logs - ERR << "Unable to restore source from " << url2.asString() - << endl; - id = 0; - ZYPP_CAUGHT(e2); - } - - if( id == 0) - { - report.append( it->url.asString() + it->product_dir.asString(), it->alias, expt ); - continue; - } - } - - DBG << "Added source as id " << id << endl; - // should not throw, we've just created the source - Source_Ref src = findSource( id ); - - if ( it->enabled ) { - DBG << "enable source" << endl; - src.enable(); - } - else { - DBG << "disable source" << endl; - src.disable(); - } - src.setAutorefresh ( it->autorefresh ); - - // user only wanted one source - if ( (alias_filter.size() > 0) && (alias_filter ==src.alias()) ) - break; + if ( (alias_filter.size() == 0) || ( alias_filter == it->alias()) ) + { + // 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; + + SourceId id = 0; + + try { + id = addSource( SourceFactory().createFrom(it->type, it->url, it->product_dir, it->alias, it->cache_dir) ); + } + catch (const Exception &expt ) + { + // Note: Url(it->url).asString() to hide password in logs + ERR << "Unable to restore source from " << Url(it->url).asString() + << endl; + + id = 0; + Url url2; + try { + url2 = it->url; + std::string scheme( url2.getScheme()); + + if( (scheme == "cd" || scheme == "dvd") && + !url2.getQueryParam("devices").empty()) + { + url2.setQueryParam("devices", ""); + + 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) ); + + // This worked ... update it->url ? + //it->url = url2.asCompleteString(); + } + } + catch (const Exception &e2) + { + // Note: Url(it->url).asString() to hide password in logs + ERR << "Unable to restore source from " << url2.asString() + << endl; + id = 0; + ZYPP_CAUGHT(e2); + } + + if( id == 0) + { + report.append( it->url.asString() + it->product_dir.asString(), it->alias, expt ); + continue; + } + } + + DBG << "Added source as id " << id << endl; + // should not throw, we've just created the source + Source_Ref src = findSource( id ); + + if ( it->enabled ) { + DBG << "enable source" << endl; + src.enable(); + } + else { + DBG << "disable source" << endl; + src.disable(); + } + src.setAutorefresh ( it->autorefresh ); + } } if( !report.empty() ) diff --git a/zypp/SourceManager.h b/zypp/SourceManager.h index 05414c0..cdd5089 100644 --- a/zypp/SourceManager.h +++ b/zypp/SourceManager.h @@ -175,7 +175,7 @@ namespace zypp * * \throws Exception */ - bool restore(Pathname root_r, bool use_caches = true, std::string alias_filter = ""); + bool restore(Pathname root_r, bool use_caches = true, const std::string &alias_filter = std::string()); /** * Find a source with a specified ID -- 2.7.4