allow for 'alias' in sources
authorKlaus Kaempf <kkaempf@suse.de>
Fri, 27 Jan 2006 12:25:25 +0000 (12:25 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Fri, 27 Jan 2006 12:25:25 +0000 (12:25 +0000)
14 files changed:
zypp/Makefile.am
zypp/Source.cc
zypp/Source.h
zypp/SourceFactory.cc
zypp/SourceFactory.h
zypp/SourceManager.cc
zypp/SourceManager.h
zypp/base/Logger.cc
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/susetags/SuseTagsImpl.h
zypp/source/yum/YUMSourceImpl.cc
zypp/source/yum/YUMSourceImpl.h

index 5744352..5af7a5a 100644 (file)
@@ -40,7 +40,6 @@ pkginclude_HEADERS = NeedAType.h \
        ResPoolManager.h\
        Package.h       \
        Pathname.h      \
-       Selection.h     \
        Source.h        \
        SourceFactory.h \
        SourceManager.h \
@@ -101,7 +100,6 @@ lib@PACKAGE@_la_SOURCES = \
        ResPoolManager.cc\
        Package.cc      \
        Pathname.cc     \
-       Selection.cc    \
        Source.cc       \
        SourceFactory.cc\
        SourceManager.cc\
index bcfe3cd..c23aa1e 100644 (file)
@@ -87,8 +87,8 @@ namespace zypp
   void Source::disable()
   { _pimpl->disable(); }
 
-  string Source::name (void) const
-  { _pimpl->name(); }
+  string Source::alias (void) const
+  { _pimpl->alias(); }
 
 
   /////////////////////////////////////////////////////////////////
index fece11f..0a6f9aa 100644 (file)
@@ -86,7 +86,7 @@ namespace zypp
 
     void disable();
 
-    std::string name (void) const;
+    std::string alias (void) const;
   };
   ///////////////////////////////////////////////////////////////////
 
index a9ae9a3..2bc993e 100644 (file)
@@ -95,7 +95,7 @@ namespace zypp
     media->close();
   }
 
-  Source SourceFactory::createFrom( const Url & url_r, const Pathname & path_r )
+  Source SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r )
   {
     if (! url_r.isValid())
       ZYPP_THROW( Exception("Empty URL passed to SourceFactory") );
@@ -107,7 +107,7 @@ namespace zypp
     try
     {
       MIL << "Trying the YUM source" << endl;
-      Source::Impl_Ptr impl = new yum::YUMSourceImpl(media, path_r);
+      Source::Impl_Ptr impl = new yum::YUMSourceImpl(media, path_r, alias_r);
       MIL << "Found the YUM source" << endl;
       return Source(impl);
     }
@@ -119,7 +119,7 @@ namespace zypp
     try
     {
       MIL << "Trying the SUSE tags source" << endl;
-      Source::Impl_Ptr impl = new susetags::SuseTagsImpl(media, path_r);
+      Source::Impl_Ptr impl = new susetags::SuseTagsImpl(media, path_r, alias_r);
       MIL << "Found the SUSE tags source" << endl;
       return Source(impl);
     }
index 9d6dd16..3b0ab64 100644 (file)
@@ -13,6 +13,7 @@
 #define ZYPP_SOURCEFACTORY_H
 
 #include <iosfwd>
+#include <string>
 
 #include "zypp/base/PtrTypes.h"
 
@@ -51,7 +52,7 @@ namespace zypp
     /** Construct source from an implementation.
      * \throw EXCEPTION on fail
     */
-    Source createFrom( const Url & url_r, const Pathname & path_r = "/" );
+    Source createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "" );
 
   private:
     /** Implementation  */
index 012dc75..6f79d3e 100644 (file)
@@ -52,9 +52,9 @@ namespace zypp
   SourceManager::~SourceManager()
   {}
 
-  unsigned SourceManager::addSource(const Url & url_r, const Pathname & path_r)
+  unsigned SourceManager::addSource(const Url & url_r, const Pathname & path_r, const std::string & name_r)
   {
-    Source src = SourceFactory().createFrom(url_r, path_r);
+    Source src = SourceFactory().createFrom(url_r, path_r, name_r);
     RW_pointer<Source> src_ptr = RW_pointer<Source>(new Source(src));
     _sources[_next_id] = src_ptr;
     return _next_id++;
@@ -76,6 +76,17 @@ namespace zypp
     }
   }
 
+  void SourceManager::removeSource(const std::string & alias_r)
+  {
+    for (SourceMap::iterator it = _sources.begin(); it != _sources.end(); ++it)
+    {
+       if (it->second->alias() == alias_r) {
+           _sources.erase(it);
+           break;
+       }
+    }
+  }
+
   void SourceManager::disableAllSources()
   {
     for( SourceMap::iterator it = _sources.begin(); it != _sources.end(); it++)
@@ -106,6 +117,22 @@ namespace zypp
     return *(it->second);
   }
 
+  Source & SourceManager::findSource(const std::string & alias_r)
+  {
+    SourceMap::iterator it;
+    for (it = _sources.begin(); it != _sources.end(); ++it)
+    {
+       if (it->second->alias() == alias_r) {
+           return *(it->second);
+           break;
+       }
+       
+    }
+    ZYPP_THROW(Exception("Unknown source name '"+alias_r+"'"));
+    /*NOTREACHED*/
+    return *(it->second); // just to keep gcc happy
+  }
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index 713ce62..7c32ae3 100644 (file)
@@ -57,11 +57,18 @@ namespace zypp
     Source & findSource(const unsigned id);
     
     /**
+     * Find a source with a specified alias
+     *
+     * \throws Exception
+     */
+    Source & findSource(const std::string & alias_r);
+    
+    /**
      * Add a new source
      *
      * \throws Exception
      */
-    unsigned addSource(const Url & url_r, const Pathname & path_r = "/");
+    unsigned addSource(const Url & url_r, const Pathname & path_r = "/", const std::string & name_r = "");
 
     /**
      * Add a new source
@@ -71,13 +78,20 @@ namespace zypp
     unsigned addSource(Source & source_r);
 
     /**
-     * Remove an existing source
+     * Remove an existing source by ID
      *
      * \throws Exception
      */
     void removeSource(const unsigned id);
 
     /**
+     * Remove an existing source by Alias
+     *
+     * \throws Exception
+     */
+    void removeSource(const std::string & alias_r);
+
+    /**
      * Disable all registered sources
      */
 #warning: this could be done by providing iterator-like methods
index 4d7c72e..1cad195 100644 (file)
@@ -46,7 +46,7 @@ namespace zypp
       {
         static std::ostream & outStr( getenv("ZYPP_NOLOG") ? noStream()
                                                            : std::cerr );
-        return outStr
+        return cerr
                  << str::form( "<%d> [%s] %s(%s):%d ",
                                level_r, group_r,
                                file_r, func_r, line_r );
index 9ca58b0..9fe1647 100644 (file)
@@ -43,12 +43,12 @@ namespace zypp
     //
     SourceImpl::SourceImpl(media::MediaAccess::Ptr & media_r,
                            const Pathname & path_r,
-                          const std::string & name_r)
+                          const std::string & alias_r)
     : _media(media_r)
     , _path(path_r)
     , _enabled(true)
     , _res_store_initialized(false)
-    , _name (name_r)
+    , _alias (alias_r)
     {}
 
     ///////////////////////////////////////////////////////////////////
index 2019695..40292da 100644 (file)
@@ -54,7 +54,7 @@ namespace zypp
       /** Ctor. */
       SourceImpl(media::MediaAccess::Ptr & media_r,
                  const Pathname & path_r = "/",
-                const std::string & name = "");
+                const std::string & alias = "");
       /** Dtor. */
       virtual ~SourceImpl();
 
@@ -94,8 +94,8 @@ namespace zypp
       void disable()
       { _enabled = false; }
 
-      std::string name (void) const
-      { return _name; }
+      std::string alias (void) const
+      { return _alias; }
 
       /** Overload to realize stream output. */
       virtual std::ostream & dumpOn( std::ostream & str ) const
@@ -110,8 +110,8 @@ namespace zypp
       Pathname _path;
       /** The source is enabled */
       bool _enabled;
-      /** (user defined) name of the source */
-      std::string _name;
+      /** (user defined) alias of the source */
+      std::string _alias;
     private:
       /** Null implementation */
       static SourceImpl_Ptr _nullimpl;
index efae659..1c2cbd5 100644 (file)
@@ -56,8 +56,8 @@ namespace zypp
       //       METHOD NAME : SuseTagsImpl::SuseTagsImpl
       //       METHOD TYPE : Ctor
       //
-      SuseTagsImpl::SuseTagsImpl( media::MediaAccess::Ptr & media_r, const Pathname & path_r )
-      : SourceImpl(media_r, path_r)
+      SuseTagsImpl::SuseTagsImpl( media::MediaAccess::Ptr & media_r, const Pathname & path_r, const std::string & alias_r )
+      : SourceImpl(media_r, path_r, alias_r)
       {
 #warning TODO check if the source is of this type
       }
index bcc7a96..2458fe4 100644 (file)
@@ -13,6 +13,7 @@
 #define ZYPP_SOURCE_SUSETAGS_SUSETAGSIMPL_H
 
 #include <iosfwd>
+#include <string>
 
 #include "zypp/Pathname.h"
 #include "zypp/source/SourceImpl.h"
@@ -40,7 +41,7 @@ namespace zypp
         */
         SuseTagsImpl( const Pathname & localDir_r );
         /** Factory ctor */
-        SuseTagsImpl( media::MediaAccess::Ptr & media_r, const Pathname & path_r = "/" );
+        SuseTagsImpl( media::MediaAccess::Ptr & media_r, const Pathname & path_r = "/", const std::string & alias_r = "");
         /** Dtor */
         ~SuseTagsImpl();
 
index 5e299c6..f52ba53 100644 (file)
@@ -48,8 +48,9 @@ namespace zypp
       /** Default ctor
       */
       YUMSourceImpl::YUMSourceImpl(media::MediaAccess::Ptr & media_r,
-                                  const Pathname & path_r)
-      : SourceImpl(media_r, path_r)
+                                  const Pathname & path_r,
+                                  const std::string & alias_r)
+      : SourceImpl(media_r, path_r, alias_r)
       {
        try {
        // first read list of all files in the reposotory
index 136ad27..266c17c 100644 (file)
@@ -46,7 +46,7 @@ namespace zypp
         YUMSourceImpl()
        {}
         /** Default ctor */
-        YUMSourceImpl(media::MediaAccess::Ptr & media_r, const Pathname & path_r = "/");
+        YUMSourceImpl(media::MediaAccess::Ptr & media_r, const Pathname & path_r = "/", const std::string & alias_r = "");
 
        virtual void createResolvables(Source & source_r);