- readRepoFile(Url) added to public API
authorJan Kupec <jkupec@suse.cz>
Fri, 15 Jun 2007 10:55:53 +0000 (10:55 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 15 Jun 2007 10:55:53 +0000 (10:55 +0000)
- repositories_in_path() -> repositories_in_dir()
- repositories_in_file() added
- what about moving repositories_in_file() to public API as
  readRepoFile(const Pathname & local_repo_file)? Can be used by clients
  to easily access info in local repo files.

zypp/RepoManager.cc
zypp/RepoManager.h

index 5698ddc..19bb801 100644 (file)
@@ -87,33 +87,47 @@ namespace zypp
   ////////////////////////////////////////////////////////////////////////////
   
   /**
+   * Reads RepoInfo's from a repo file.
+   *
+   * \param file pathname of the file to read.
+   */
+  static std::list<RepoInfo> repositories_in_file( const Pathname & file )
+  {
+    MIL << "repo file: " << file << endl;
+    RepoCollector collector;
+    parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
+    return collector.repos;
+  }
+
+  ////////////////////////////////////////////////////////////////////////////
+  
+  /**
    * \short List of RepoInfo's from a directory
    *
    * Goes trough every file in a directory and adds all
    * RepoInfo's contained in that file.
    *
-   * \param file pathname of the file to read.
+   * \param dir pathname of the directory to read.
    */
-  static std::list<RepoInfo> repositories_in_path( const Pathname &dir )
+  static std::list<RepoInfo> repositories_in_dir( const Pathname &dir )
   {
-    MIL << " " << dir << endl;
-    RepoCollector collector;
-    std::list<RepoInfo> repos;
+    MIL << "directory " << dir << endl;
+    list<RepoInfo> repos;
     list<Pathname> entries;
     if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 )
       ZYPP_THROW(Exception("failed to read directory"));
     
     for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
     {
-      Pathname file = *it;
-      parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
+      list<RepoInfo> tmp = repositories_in_file( *it ); 
+      repos.insert( repos.end(), tmp.begin(), tmp.end() );
 
       //std::copy( collector.repos.begin(), collector.repos.end(), std::back_inserter(repos));
       //MIL << "ok" << endl;
     }
-    return collector.repos;
+    return repos;
   }
-  
+
   ////////////////////////////////////////////////////////////////////////////
   
   static void assert_alias( const RepoInfo &info )
@@ -203,14 +217,33 @@ namespace zypp
   {}
   
   ////////////////////////////////////////////////////////////////////////////
-  
+
   std::list<RepoInfo> RepoManager::knownRepositories() const
   {
     MIL << endl;
-    return repositories_in_path("/etc/zypp/repos.d");
+    return repositories_in_dir("/etc/zypp/repos.d");
     MIL << endl;
   }
-  
+
+  ////////////////////////////////////////////////////////////////////////////
+
+  std::list<RepoInfo> RepoManager::readRepoFile(const Url & repo_file) const
+  {
+
+    // no interface to download a specific file, using workaround:
+    //! \todo add MediaManager::provideFile(Url file_url) to easily access any file URLs? (no need for media access id or media_nr)  
+    Url url(repo_file);
+    Pathname path(url.getPathName());
+    url.setPathName ("/");
+
+    MediaSetAccess access(url);
+    Pathname local = access.provideFile(path);
+
+    DBG << "reading repo file " << repo_file << ", local path: " << local << endl;
+
+    return repositories_in_file(local);
+  }
+
   ////////////////////////////////////////////////////////////////////////////
   
   void RepoManager::refreshMetadata( const RepoInfo &info )
index 1d90d36..8c15294 100644 (file)
@@ -65,10 +65,19 @@ namespace zypp
     * The known repositories are read from
     * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
     * Which defaults to ZYpp global settings.
-    *
+    * \return found list<RepoInfo>
     */
    std::list<RepoInfo> knownRepositories() const;
-   
+
+    /**
+     * Parses \a repo_file and returns a list of \ref RepoInfo objects
+     * corresponding to repositories found within the file.
+     * 
+     * \param repo_file Valid URL of the repo file.
+     * \return found list<RepoInfo>
+     */
+    std::list<RepoInfo> readRepoFile(const Url & repo_file) const;
+
    /**
     * \short Refresh local raw cache
     *
@@ -158,8 +167,12 @@ namespace zypp
     * one or more repositories.
     */
    //void addRepositories( const Url &url );
-   
-   
+
+    /**
+     * PROPOSAL
+     */
+    void removeRepository( const std::string & alias );
+
   public:
 
   private: