New static RepoManager::makeStupidAlias([Url]) returning a repo alias
authorMichael Andres <ma@suse.de>
Fri, 6 Mar 2009 16:17:55 +0000 (17:17 +0100)
committerMichael Andres <ma@suse.de>
Fri, 6 Mar 2009 16:18:41 +0000 (17:18 +0100)
if nothing better is available.

zypp/RepoManager.cc
zypp/RepoManager.h

index f14291d..e3ec3a2 100644 (file)
@@ -602,6 +602,26 @@ namespace zypp
     return false;
   }
 
+  std::string makeStupidAlias( const Url & url_r )
+  {
+    std::string ret( url_r.getScheme() );
+    if ( ret.empty() )
+      ret = "repo-";
+    else
+      ret += "-";
+
+    std::string host( url_r.getHost() );
+    if ( ! host.empty() )
+    {
+      ret += host;
+      ret += "-";
+    }
+
+    static Date::ValueType serial = Date::now();
+    ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
+    return ret;
+  }
+
   ////////////////////////////////////////////////////////////////////////////
 
   Pathname RepoManager::metadataPath( const RepoInfo &info ) const
index fdeb482..3196d38 100644 (file)
@@ -172,6 +172,11 @@ namespace zypp
     /** \overload Take alias from RepoInfo. */
     bool hasRepo( const RepoInfo & info_r ) const
     { return hasRepo( info_r.alias() ); }
+
+    /** Some stupid string but suitable as alias for your url if nothing better is available.
+     * Something like \c "http-download.opensuse.org-83df67e5"
+    */
+    static std::string makeStupidAlias( const Url & url_r = Url() );
    //@}
 
    /**