From 9dea42b7ab2ca5dd396eea24639cedb1f52e83b1 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Mon, 14 Jul 2014 17:45:54 +0200 Subject: [PATCH] refreshService: add option to force repo status reset --- zypp/RepoManager.cc | 69 +++++++++++++++++++++++++++++++++-------------------- zypp/RepoManager.h | 18 ++++++++++---- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 7a46699..73eea25 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -497,11 +497,11 @@ namespace zypp void removeService( const ServiceInfo & service ) { removeService( service.alias() ); } - void refreshServices(); + void refreshServices( const RefreshServiceOptions & options_r ); - void refreshService( const std::string & alias ); - void refreshService( const ServiceInfo & service ) - { refreshService( service.alias() ); } + void refreshService( const std::string & alias, const RefreshServiceOptions & options_r ); + void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r ) + { refreshService( service.alias(), options_r ); } void modifyService( const std::string & oldAlias, const ServiceInfo & newService ); @@ -1804,7 +1804,7 @@ namespace zypp //////////////////////////////////////////////////////////////////////////// - void RepoManager::Impl::refreshServices() + void RepoManager::Impl::refreshServices( const RefreshServiceOptions & options_r ) { // copy the set of services since refreshService // can eventually invalidate the iterator @@ -1815,14 +1815,14 @@ namespace zypp continue; try { - refreshService(*it); + refreshService(*it, options_r); } catch ( const repo::ServicePluginInformalException & e ) { ;/* ignore ServicePluginInformalException */ } } } - void RepoManager::Impl::refreshService( const std::string & alias ) + void RepoManager::Impl::refreshService( const std::string & alias, const RefreshServiceOptions & options_r ) { ServiceInfo service( getService( alias ) ); assert_alias( service ); @@ -1831,7 +1831,7 @@ namespace zypp // Either when probing the type, or when adjusting the repositories // enable/disable state.: bool serviceModified = false; - MIL << "Going to refresh service '" << service.alias() << "', url: "<< service.url() << endl; + MIL << "Going to refresh service '" << service.alias() << "', url: "<< service.url() << ", opts: " << options_r << endl; //! \todo add callbacks for apps (start, end, repo removed, repo added, repo changed) @@ -1954,23 +1954,35 @@ namespace zypp TriBool toBeEnabled( indeterminate ); // indeterminate - follow the service request DBG << "Service request to " << (it->enabled()?"enable":"disable") << " service repo " << it->alias() << endl; - if ( service.repoToEnableFind( it->alias() ) ) + if ( options_r.testFlag( RefreshService_restoreStatus ) ) { - DBG << "User request to enable service repo " << it->alias() << endl; - toBeEnabled = true; - // Remove from enable request list. - // NOTE: repoToDisable is handled differently. - // It gets cleared on each refresh. - service.delRepoToEnable( it->alias() ); - serviceModified = true; + DBG << "Opt RefreshService_restoreStatus " << it->alias() << endl; + // this overrides any pending request! + // Remove from enable request list. + // NOTE: repoToDisable is handled differently. + // It gets cleared on each refresh. + service.delRepoToEnable( it->alias() ); + // toBeEnabled stays indeterminate! } - else if ( service.repoToDisableFind( it->alias() ) ) + else { - DBG << "User request to disable service repo " << it->alias() << endl; - toBeEnabled = false; + if ( service.repoToEnableFind( it->alias() ) ) + { + DBG << "User request to enable service repo " << it->alias() << endl; + toBeEnabled = true; + // Remove from enable request list. + // NOTE: repoToDisable is handled differently. + // It gets cleared on each refresh. + service.delRepoToEnable( it->alias() ); + serviceModified = true; + } + else if ( service.repoToDisableFind( it->alias() ) ) + { + DBG << "User request to disable service repo " << it->alias() << endl; + toBeEnabled = false; + } } - RepoInfoList::iterator oldRepo( findAlias( it->alias(), oldRepos ) ); if ( oldRepo == oldRepos.end() ) { @@ -1994,6 +2006,11 @@ namespace zypp // NOTE: Assert toBeEnabled is boolean afterwards! if ( oldRepo->enabled() == it->enabled() ) toBeEnabled = it->enabled(); // service requests no change to the system + else if (options_r.testFlag( RefreshService_restoreStatus ) ) + { + toBeEnabled = it->enabled(); // RefreshService_restoreStatus forced + DBG << "Opt RefreshService_restoreStatus " << it->alias() << " forces " << (toBeEnabled?"enabled":"disabled") << endl; + } else { const auto & last = service.repoStates().find( oldRepo->alias() ); @@ -2337,14 +2354,14 @@ namespace zypp void RepoManager::removeService( const ServiceInfo & service ) { return _pimpl->removeService( service ); } - void RepoManager::refreshServices() - { return _pimpl->refreshServices(); } + void RepoManager::refreshServices( const RefreshServiceOptions & options_r ) + { return _pimpl->refreshServices( options_r ); } - void RepoManager::refreshService( const std::string & alias ) - { return _pimpl->refreshService( alias ); } + void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r ) + { return _pimpl->refreshService( alias, options_r ); } - void RepoManager::refreshService( const ServiceInfo & service ) - { return _pimpl->refreshService( service ); } + void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r ) + { return _pimpl->refreshService( service, options_r ); } void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service ) { return _pimpl->modifyService( oldAlias, service ); } diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 0de55e5..8717b9f 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -17,6 +17,7 @@ #include "zypp/base/PtrTypes.h" #include "zypp/base/Iterator.h" +#include "zypp/base/Flags.h" #include "zypp/Pathname.h" #include "zypp/ZConfig.h" @@ -141,10 +142,16 @@ namespace zypp BuildForced }; - enum RepoRemovePolicy + /** Flags for tuning RefreshService */ + enum RefreshServiceBit { - + RefreshService_restoreStatus = (1<<0) ///< Force restoring repo enabled/disabled staus }; + ZYPP_DECLARE_FLAGS(RefreshServiceFlags,RefreshServiceBit); + + /** Options tuning RefreshService */ + typedef RefreshServiceFlags RefreshServiceOptions; + /** \name Known repositories. * @@ -591,7 +598,7 @@ namespace zypp * * \see refreshService(ServiceInfo) */ - void refreshServices(); + void refreshServices( const RefreshServiceOptions & options_r = RefreshServiceOptions() ); /** * Refresh specific service. @@ -601,9 +608,9 @@ namespace zypp * \throws RepoException if service is not found. * \throws MediaException If there's a problem downloading the repo index file. */ - void refreshService( const std::string & alias ); + void refreshService( const std::string & alias, const RefreshServiceOptions & options_r = RefreshServiceOptions() ); /** \overload Take alias from ServiceInfo */ - void refreshService( const ServiceInfo & service ); + void refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r = RefreshServiceOptions() ); /** * Modifies service file (rewrites it with new values) and underlying @@ -689,6 +696,7 @@ namespace zypp /** Pointer to implementation */ RWCOW_pointer _pimpl; }; + ZYPP_DECLARE_OPERATORS_FOR_FLAGS(RepoManager::RefreshServiceFlags); /////////////////////////////////////////////////////////////////// /** \relates RepoManager Stream output */ -- 2.7.4