[yast-commit] r51767 - in /trunk/pkg-bindings/src: Service.cc ServiceManager.cc ServiceManager.h Source_Get.cc Source_Load.cc
Author: lslezak Date: Wed Oct 1 18:39:48 2008 New Revision: 51767 URL: http://svn.opensuse.org/viewcvs/yast?rev=51767&view=rev Log: - fixed exception handling in Pkg::Service*() functions, the description the exceptions can be read using Pkg::LastError() Modified: trunk/pkg-bindings/src/Service.cc trunk/pkg-bindings/src/ServiceManager.cc trunk/pkg-bindings/src/ServiceManager.h trunk/pkg-bindings/src/Source_Get.cc trunk/pkg-bindings/src/Source_Load.cc Modified: trunk/pkg-bindings/src/Service.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Service.cc?rev=51767&r1=51766&r2=51767&view=diff ============================================================================== --- trunk/pkg-bindings/src/Service.cc (original) +++ trunk/pkg-bindings/src/Service.cc Wed Oct 1 18:39:48 2008 @@ -74,8 +74,9 @@ return YCPBoolean(service_manager.AddService(alias->value(), url->value())); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -99,8 +100,9 @@ return YCPBoolean(service_manager.RemoveService(alias->value())); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -209,8 +211,9 @@ return YCPBoolean(service_manager.SetService(old_alias->value(), s)); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -226,10 +229,12 @@ try { zypp::RepoManager repomanager = CreateRepoManager(); - return YCPBoolean(service_manager.SaveServices(repomanager)); + service_manager.SaveServices(repomanager); + return YCPBoolean(true); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -245,10 +250,12 @@ try { zypp::RepoManager repomanager = CreateRepoManager(); - return YCPBoolean(service_manager.LoadServices(repomanager)); + service_manager.LoadServices(repomanager); + return YCPBoolean(true); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -273,8 +280,9 @@ zypp::RepoManager repomanager = CreateRepoManager(); return YCPBoolean(service_manager.RefreshService(alias->value(), repomanager)); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); } return YCPBoolean(false); @@ -309,8 +317,9 @@ const zypp::RepoManager repomanager = CreateRepoManager(); return YCPString(service_manager.Probe(zypp::Url(url->asString()->value()), repomanager)); } - catch(...) + catch (const zypp::Exception& excpt) { + _last_error.setLastError(ExceptionAsString(excpt)); return YCPVoid(); } } Modified: trunk/pkg-bindings/src/ServiceManager.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/ServiceManager.cc?rev=51767&r1=51766&r2=51767&view=diff ============================================================================== --- trunk/pkg-bindings/src/ServiceManager.cc (original) +++ trunk/pkg-bindings/src/ServiceManager.cc Wed Oct 1 18:39:48 2008 @@ -32,107 +32,69 @@ { } -bool ServiceManager::LoadServices(const zypp::RepoManager &repomgr) +void ServiceManager::LoadServices(const zypp::RepoManager &repomgr) { - bool ret = true; - if (!_services_loaded) { - try - { - for_ (it, repomgr.serviceBegin(), repomgr.serviceEnd()) - { - // set the original alias to the current one - PkgService s(*it, it->alias()); - y2milestone("Loaded service %s (%s)", s.alias().c_str(), s.url().asString().c_str()); - _known_services.insert(std::make_pair(s.alias(), s)); - } - - _services_loaded = true; - } - catch(...) + for_ (it, repomgr.serviceBegin(), repomgr.serviceEnd()) { - ret = false; + // set the original alias to the current one + PkgService s(*it, it->alias()); + y2milestone("Loaded service %s (%s)", s.alias().c_str(), s.url().asString().c_str()); + _known_services.insert(std::make_pair(s.alias(), s)); } + + _services_loaded = true; } else { y2warning("Services have already been loaded, skipping load"); } - - return ret; } -bool ServiceManager::SaveServices(zypp::RepoManager &repomgr) const +void ServiceManager::SaveServices(zypp::RepoManager &repomgr) const { - bool ret = true; - for_ (it, _known_services.begin(), _known_services.end()) { std::string alias(it->second.alias()); - try - { // delete if (it->second.isDeleted()) { y2milestone("Removing service %s", alias.c_str()); repomgr.removeService(alias); } - } - catch(...) - { - y2error("Cannot delete service %s", alias.c_str()); - ret = false; - } } for_ (it, _known_services.begin(), _known_services.end()) { std::string alias(it->second.alias()); - try + // save + if (!it->second.isDeleted()) { - // save - if (!it->second.isDeleted()) + if (it->second != repomgr.getService(alias)) { - if (it->second != repomgr.getService(alias)) - { - y2milestone("Saving modified service %s", alias.c_str()); - // FIXME use old alias - repomgr.modifyService(alias, it->second); - } + y2milestone("Saving modified service %s", alias.c_str()); + // FIXME use old alias + repomgr.modifyService(alias, it->second); } } - catch(...) - { - y2error("Cannot save service %s", alias.c_str()); - ret = false; - } } - - return ret; } bool ServiceManager::RefreshService(const std::string &alias, zypp::RepoManager &repomgr) { - try - { - PkgServices::iterator serv_it = _known_services.find(alias); - - if (serv_it == _known_services.end()) - { - y2error("Service '%s' does not exist", alias.c_str()); - return false; - } + PkgServices::iterator serv_it = _known_services.find(alias); - repomgr.refreshService(serv_it->second); - return true; - } - catch(...) + if (serv_it == _known_services.end()) { + y2error("Service '%s' does not exist", alias.c_str()); return false; } + + repomgr.refreshService(serv_it->second); + return true; } ServiceManager::Services ServiceManager::GetServices() const @@ -153,84 +115,68 @@ bool ServiceManager::AddService(const std::string &alias, const std::string &url) { - try + if (alias.empty()) { - if (alias.empty()) - { - y2error("Empty alias for service %s", url.c_str()); - return false; - } + y2error("Empty alias for service %s", url.c_str()); + return false; + } - PkgServices::iterator serv_it = _known_services.find(alias); - std::string orig_alias; + PkgServices::iterator serv_it = _known_services.find(alias); + std::string orig_alias; - if (serv_it != _known_services.end()) + if (serv_it != _known_services.end()) + { + if (serv_it->second.isDeleted()) { - if (serv_it->second.isDeleted()) - { - // remember the original alias - // adding a removed service is the same as changing existing one - orig_alias = serv_it->second.alias(); - - // we are adding an already removed service, - // remove the existing service - _known_services.erase(serv_it); - } - else - { - y2error("Service with alias %s already exists", alias.c_str()); - return false; - } + // remember the original alias + // adding a removed service is the same as changing existing one + orig_alias = serv_it->second.alias(); + + // we are adding an already removed service, + // remove the existing service + _known_services.erase(serv_it); } + else + { + y2error("Service with alias %s already exists", alias.c_str()); + return false; + } + } - zypp::ServiceInfo info; - info.setAlias(alias); - info.setUrl(url); + zypp::ServiceInfo info; + info.setAlias(alias); + info.setUrl(url); - PkgService srv(info, orig_alias); + PkgService srv(info, orig_alias); - _known_services.insert(std::make_pair(alias, srv)); - } - catch(...) - { - return false; - } + _known_services.insert(std::make_pair(alias, srv)); return true; } bool ServiceManager::RemoveService(const std::string &alias) { - try - { - PkgServices::iterator serv_it = _known_services.find(alias); + PkgServices::iterator serv_it = _known_services.find(alias); - if (serv_it != _known_services.end()) + if (serv_it != _known_services.end()) + { + if (serv_it->second.isDeleted()) { - if (serv_it->second.isDeleted()) - { - y2warning("Service %s has been already removed", alias.c_str()); - return true; - } - else - { - serv_it->second.setDeleted(); - y2milestone("Service %s has been marked as deleted", alias.c_str()); - return true; - } + y2warning("Service %s has been already removed", alias.c_str()); + return true; } else { - y2error("Service %s does not exist", alias.c_str()); - return false; + serv_it->second.setDeleted(); + y2milestone("Service %s has been marked as deleted", alias.c_str()); + return true; } } - catch(...) + else { + y2error("Service %s does not exist", alias.c_str()); return false; } - - return true; } void ServiceManager::Reset() @@ -244,30 +190,24 @@ zypp::ServiceInfo ServiceManager::GetService(const std::string &alias) const { - try - { - PkgServices::const_iterator serv_it = _known_services.find(alias); + PkgServices::const_iterator serv_it = _known_services.find(alias); - if (serv_it != _known_services.end()) + if (serv_it != _known_services.end()) + { + if (serv_it->second.isDeleted()) { - if (serv_it->second.isDeleted()) - { - y2warning("Service %s has been removed", alias.c_str()); - return zypp::ServiceInfo::noService; - } - else - { - return serv_it->second; - } + y2warning("Service %s has been removed", alias.c_str()); + return zypp::ServiceInfo::noService; } else { - y2error("Service %s does not exist", alias.c_str()); - return zypp::ServiceInfo::noService; + return serv_it->second; } } - catch(...) + else { + y2error("Service %s does not exist", alias.c_str()); + return zypp::ServiceInfo::noService; } return zypp::ServiceInfo::noService; @@ -275,43 +215,37 @@ bool ServiceManager::SetService(const std::string old_alias, const zypp::ServiceInfo &srv) { - try - { - PkgServices::const_iterator serv_it = _known_services.find(old_alias); + PkgServices::const_iterator serv_it = _known_services.find(old_alias); - if (serv_it != _known_services.end()) + if (serv_it != _known_services.end()) + { + if (serv_it->second.isDeleted()) + { + y2warning("Service %s has been removed", old_alias.c_str()); + return false; + } + else { - if (serv_it->second.isDeleted()) + // if the alias has been already changed then keep the original alias + if (old_alias == serv_it->second.alias() ) { - y2warning("Service %s has been removed", old_alias.c_str()); - return false; + PkgService s(srv, old_alias); + _known_services[srv.alias()] = s; } else { - // if the alias has been already changed then keep the original alias - if (old_alias == serv_it->second.alias() ) - { - PkgService s(srv, old_alias); - _known_services[srv.alias()] = s; - } - else - { - // keep the old alias - PkgService s(srv, serv_it->second.origAlias()); - _known_services[srv.alias()] = s; - } - - return true; + // keep the old alias + PkgService s(srv, serv_it->second.origAlias()); + _known_services[srv.alias()] = s; } - } - else - { - y2error("Service %s does not exist", old_alias.c_str()); - return false; + + return true; } } - catch(...) + else { + y2error("Service %s does not exist", old_alias.c_str()); + return false; } return false; Modified: trunk/pkg-bindings/src/ServiceManager.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/ServiceManager.h?rev=51767&r1=51766&r2=51767&view=diff ============================================================================== --- trunk/pkg-bindings/src/ServiceManager.h (original) +++ trunk/pkg-bindings/src/ServiceManager.h Wed Oct 1 18:39:48 2008 @@ -40,9 +40,9 @@ Services GetServices() const; - bool LoadServices(const zypp::RepoManager &repomgr); + void LoadServices(const zypp::RepoManager &repomgr); - bool SaveServices(zypp::RepoManager &repomgr) const; + void SaveServices(zypp::RepoManager &repomgr) const; bool AddService(const std::string &alias, const std::string &url); Modified: trunk/pkg-bindings/src/Source_Get.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Source_Get.cc?rev=51767&r1=51766&r2=51767&view=diff ============================================================================== --- trunk/pkg-bindings/src/Source_Get.cc (original) +++ trunk/pkg-bindings/src/Source_Get.cc Wed Oct 1 18:39:48 2008 @@ -370,8 +370,10 @@ * source priority (highest first). A source state is a map: * $[ * "SrcId" : YCPInteger, - * "enabled" : YCPBoolean - * "autorefresh": YCPBoolean + * "enabled" : YCPBoolean, + * "autorefresh": YCPBoolean, + * "name" : YCPString, + * "service" : YCPString * ]; * * @return list<map> list of source states (map) @@ -395,6 +397,7 @@ src_map->add(YCPString("autorefresh"), YCPBoolean((*it)->repoInfo().autorefresh())); src_map->add(YCPString("name"), YCPString((*it)->repoInfo().name())); src_map->add(YCPString("priority"), YCPInteger((*it)->repoInfo().priority())); + src_map->add(YCPString("service"), YCPString((*it)->repoInfo().service())); ret->add(src_map); } Modified: trunk/pkg-bindings/src/Source_Load.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Source_Load.cc?rev=51767&r1=51766&r2=51767&view=diff ============================================================================== --- trunk/pkg-bindings/src/Source_Load.cc (original) +++ trunk/pkg-bindings/src/Source_Load.cc Wed Oct 1 18:39:48 2008 @@ -52,6 +52,7 @@ YCPValue PkgFunctions::SourceRestore() { + if (repos.size() > 0) { y2warning("Number of registered repositories: %zd, skipping repository load!", repos.size()); @@ -495,7 +496,7 @@ } /**************************************************************************************** - * @builtin SourceCleanupBroken + * @builtin SourceCleanupBroken - obsoleted, do not use! * * @short Clean up all sources that were not properly restored on the last * call of SourceStartManager or SourceStartCache. -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org