- implement repo.add.probe option
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 3 Aug 2007 14:39:19 +0000 (14:39 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 3 Aug 2007 14:39:19 +0000 (14:39 +0000)
zypp/RepoManager.cc
zypp/RepoManager.h
zypp/ZConfig.cc
zypp/ZConfig.h
zypp/repo/RepoException.h

index 5e639f8..e2a0f35 100644 (file)
@@ -575,23 +575,34 @@ namespace zypp
       return repo::RepoType::NONE;
     }
 
-    MediaSetAccess access(url);
-    if ( access.doesFileExist("/repodata/repomd.xml") )
-      return repo::RepoType::RPMMD;
-    if ( access.doesFileExist("/content") )
-      return repo::RepoType::YAST2;
-
-    // if it is a local url of type dir
-    if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) )
+    try
     {
-      Pathname path = Pathname(url.getPathName());
-      if ( PathInfo(path).isDir() )
+      MediaSetAccess access(url);
+      if ( access.doesFileExist("/repodata/repomd.xml") )
+        return repo::RepoType::RPMMD;
+      if ( access.doesFileExist("/content") )
+        return repo::RepoType::YAST2;
+  
+      // if it is a local url of type dir
+      if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) )
       {
-        // allow empty dirs for now
-        return repo::RepoType::RPMPLAINDIR;
+        Pathname path = Pathname(url.getPathName());
+        if ( PathInfo(path).isDir() )
+        {
+          // allow empty dirs for now
+          return repo::RepoType::RPMPLAINDIR;
+        }
       }
     }
-
+    catch ( const media::MediaException &e )
+    {
+      ZYPP_THROW(RepoException("Error trying to read from " + url.asString()));
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_THROW(Exception("Unknown error reading from " + url.asString()));
+    }
+    
     return repo::RepoType::NONE;
   }
 
@@ -744,13 +755,29 @@ namespace zypp
         ZYPP_THROW(RepoAlreadyExistsException(info.alias()));
     }
 
+    RepoInfo tosave = info;
+    
+    // check the first url for now
+    if ( ZConfig::instance().repo_add_probe() || ( tosave.type() == RepoType::NONE ) )
+    {
+      RepoType probedtype;
+      probedtype = probe(*tosave.baseUrlsBegin());
+      if ( tosave.baseUrlsSize() > 0 )
+      {
+        if ( probedtype == RepoType::NONE )
+          ZYPP_THROW(RepoUnknownTypeException());
+        else
+          tosave.setType(probedtype);
+      }
+    }
+    
     progress.set(50);
 
     // assert the directory exists
     filesystem::assert_dir(_pimpl->options.knownReposPath);
 
     Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
-                                                    generate_filename(info));
+                                                    generate_filename(tosave));
     // now we have a filename that does not exists
     MIL << "Saving repo in " << repofile << endl;
 
@@ -759,7 +786,7 @@ namespace zypp
       ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
     }
 
-    info.dumpRepoOn(file);
+    tosave.dumpRepoOn(file);
     progress.toMax();
     MIL << "done" << endl;
   }
index 1801efe..d93bb67 100644 (file)
@@ -222,8 +222,11 @@ namespace zypp
     *
     * \throws repo::RepoAlreadyExistsException If the repo clash some 
     * unique attribute like alias
-    *
-    * \throws RepoAlreadyExistsException
+    * \throws MediaException If the access to the url fails
+    * \throws ParseException If the file parsing fails
+    * \throws RepoUnknownType If repository type can't be determined
+    * \throws RepoException ON other repository related errors
+    * \throws Exception On other errors.
     */
    void addRepository( const RepoInfo &info,
                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
@@ -238,6 +241,8 @@ namespace zypp
     * \throws RepoAlreadyExistsException
     * \throws MediaException If the access to the url fails
     * \throws ParseException If the file parsing fails
+    * \throws RepoUnknownType If repository type can't be determined
+    * \throws RepoException ON other repository related errors
     * \throws Exception On other errors.
     */
     void addRepositories( const Url &url,
index c2c451e..a31666d 100644 (file)
@@ -36,6 +36,7 @@ namespace zypp
   {
     public:
       Impl()
+        : repo_add_probe(false)
       {
         MIL << "ZConfig singleton created." << endl;
         Pathname confpath("/etc/zypp/zypp.conf");
@@ -80,6 +81,10 @@ namespace zypp
               {
                 cfg_cache_path = Pathname(value);
               }
+              else if ( entry == "repo.add.probe" )
+              {
+                repo_add_probe = (value == "1");
+              }
             }
             
           }
@@ -99,6 +104,8 @@ namespace zypp
     Pathname cfg_cache_path;
     Pathname cfg_known_repos_path;
     
+    bool repo_add_probe;
+    
   };
   ///////////////////////////////////////////////////////////////////
 
@@ -180,6 +187,11 @@ namespace zypp
     return s;
   }
 
+  bool ZConfig::repo_add_probe() const
+  {
+    return _pimpl->repo_add_probe;
+  }
+  
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index ec77784..79ef4c0 100644 (file)
@@ -73,6 +73,13 @@ namespace zypp
        */
       const std::string & cacheDBSplitJoinSeparator() const;
 
+      /**
+       * Whether repository urls should be probed.
+       / config option
+       * repo.add.probe
+       */
+      bool repo_add_probe() const;
+      
     public:
       class Impl;
       /** Dtor */
index f128753..ab8c6f1 100644 (file)
@@ -118,7 +118,7 @@ namespace zypp
     
     /**
      * thrown when it was impossible to
-     * determine an alias for this repo.
+     * determine this repo type.
      */
     class RepoUnknownTypeException : public RepoException
     {