- fixed service removal
authorJan Kupec <jkupec@suse.cz>
Sun, 27 Jul 2008 11:33:17 +0000 (11:33 +0000)
committerJan Kupec <jkupec@suse.cz>
Sun, 27 Jul 2008 11:33:17 +0000 (11:33 +0000)
zypp/RepoManager.cc
zypp/RepoManager.h
zypp/Service.cc

index 136b687..63fcf03 100644 (file)
@@ -1328,7 +1328,7 @@ namespace zypp
   {
     MIL << "Going to delete repo " << alias << endl;
 
-    const Service& service = getService( alias );
+    const Service & service = getService( alias );
 
     Pathname location = service.location();
     if( location.empty() )
@@ -1342,7 +1342,8 @@ namespace zypp
     parser::ServiceFileReader reader( location,
         bind(&Impl::ServiceCollector::collect,collector,_1) );
 
-    if ( tmpSet.size() == 1 ) //only one record
+    // only one service definition in the file
+    if ( tmpSet.size() == 1 ) 
     {
       if ( filesystem::unlink(location) != 0 )
       {
@@ -1367,13 +1368,21 @@ namespace zypp
       MIL << alias << " sucessfully deleted from file " << location <<  endl;
     }
 
-    //now remove all repositories added by this service
+    // now remove all repositories added by this service
+    RepoCollector rcollector;
     getRepositoriesInService( alias,
       boost::make_function_output_iterator(
-        bind(&RepoManager::removeRepository, this, _1, ProgressData::ReceiverFnc()) ) );
+          bind( &RepoCollector::collect, &rcollector, _1 ) ) );
+    // cannot do this directly in getRepositoriesInService - would invalidate iterators
+    for_(rit, rcollector.repos.begin(), rcollector.repos.end())
+      removeRepository(*rit);
   }
 
 
+  void RepoManager::removeService( const Service & service )
+  { removeService(service.alias()); }
+
+
   void RepoManager::Impl::saveService( const Service & service ) const
   {
     filesystem::assert_dir( options.knownServicesPath );
@@ -1396,11 +1405,10 @@ namespace zypp
 
   Service RepoManager::getService( const std::string & alias ) const
   {
-    ServiceConstIterator it = _pimpl->services.find(alias);
-    if ( it == serviceEnd() )
-      return Service::noService;
-    else
-      return *it;
+    for_ (it, serviceBegin(), serviceEnd())
+      if ( it->alias() == alias )
+        return *it;
+    return Service::noService;
   }
 
   bool RepoManager::serviceEmpty() const { return _pimpl->services.empty(); }
index 31a52c3..ee0dc3c 100644 (file)
@@ -474,6 +474,8 @@ namespace zypp
      */
     void removeService( const std::string & alias );
 
+    void removeService( const Service & service );
+
     /**
      * Gets true if no service is in RepoManager (so no one in specified location)
      *
@@ -556,39 +558,51 @@ namespace zypp
     };
 
   public:
+
     /**
      * fill to output iterator repositories in service name. This output iterator can perform
      * any action on with Repo or service Container, because it is sets and it isn't dynamic recreate.
-     * \param name service name
-     * \param out output iterator which get all repositories in Service
+     *
+     * \note Don't use this function with RepoManager::removeRepository(), it will lead to segfaults
+     *       due to invalidated internal iterators. FIXME can this be solved (using STL) so that this
+     *       warning would not be needed?
+     *
+     * \param alias service alias
+     * \param out output iterator which get all the repositories belonging to
+     *   specified service
      *
      * example how set priority for each RepoInfo in this service:
      * \code
      * //functor
-     * class ChangePriority{
-     *   private:
-     *     int priority;
-     *   public:
-     *     ChangePriority(int prio) : priority(prio) {}
-     *     void doIt( RepoInfo info ) { info.setPriority(priority); } //missing rewrite priority back via RepoManager::modifyRepo
+     * class ChangePriority
+     * {
+     * private:
+     *   int priority;
+     * public:
+     *   ChangePriority(int prio) : priority(prio) {}
+     *   // missing rewrite priority back via RepoManager::modifyRepo
+     *   void doIt( RepoInfo info ) { info.setPriority(priority); } 
      * }
      *
      * //somewhere in code
      * ChangePriority changer(10);
-     * getRepositoriesInService(name,getRepositoriesInService( name, boost::make_function_output_iterator(bind(&ChangePriority::doIt, &changer, _1))));
+     * getRepositoriesInService(name,
+     *   boost::make_function_output_iterator(
+     *     bind(&ChangePriority::doIt, &changer, _1)));
      * \endcode
      */
-
     template<typename OutputIterator>
     void getRepositoriesInService( const std::string & alias,
                                    OutputIterator out ) const
     {
       MatchServiceAlias filter(alias);
 
-      std::copy(boost::make_filter_iterator(bind(&MatchServiceAlias::match,
-          filter, _1),repoBegin(),repoEnd()), boost::make_filter_iterator(
+      std::copy(
+        boost::make_filter_iterator(
+          bind(&MatchServiceAlias::match, filter, _1), repoBegin(), repoEnd()),
+        boost::make_filter_iterator(
           bind(&MatchServiceAlias::match, filter, _1), repoEnd(), repoEnd()),
-          out );
+        out);
     }
 
   protected:
index 052282a..6852103 100644 (file)
@@ -83,12 +83,10 @@ namespace zypp
 
   void Service::dumpServiceOn( std::ostream& str ) const
   {
-    str << endl;
     str << "[" << alias() << "]" << endl;
     str << "name = " << name() << endl;
     str << "url = " << url() << endl;
     str << "enabled = " << ( enabled() ? "1" : "0") << endl;
-    str << endl;
   }
 
   Pathname Service::location() const