fix logic here, we want to restore only the source with alias A not till we find...
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 9 Jun 2006 16:06:28 +0000 (16:06 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 9 Jun 2006 16:06:28 +0000 (16:06 +0000)
zypp/SourceManager.cc
zypp/SourceManager.h

index f7af063..28f2443 100644 (file)
@@ -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<storage::PersistentStorage::SourceData>::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() )
index 05414c0..cdd5089 100644 (file)
@@ -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