arch and basearch working
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 30 Jul 2007 21:55:39 +0000 (21:55 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 30 Jul 2007 21:55:39 +0000 (21:55 +0000)
tests/repo/RepoVariables_test.cc
zypp/RepoInfo.cc
zypp/RepoInfo.h
zypp/RepoManager.cc
zypp/repo/PackageProvider.cc
zypp/repo/RepoVariables.cc

index 85f3638..44289a5 100644 (file)
@@ -7,13 +7,13 @@
 #include <boost/test/parameterized_test.hpp>
 #include <boost/test/unit_test_log.hpp>
 
+#include "zypp/ZYppFactory.h"
 #include "zypp/Url.h"
 #include "zypp/PathInfo.h"
 #include "zypp/TmpPath.h"
 #include "zypp/ZConfig.h"
 #include "zypp/repo/RepoVariables.h"
 
-
 using std::cout;
 using std::endl;
 using std::string;
@@ -28,6 +28,10 @@ void replace_test(const string &dir)
   
   BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar"),
                     "http://foo/"+ ZConfig::instance().systemArchitecture().asString() + "/bar");
+
+  getZYpp()->setArchitecture(Arch("i686"));
+  BOOST_CHECK_EQUAL(replacer("http://foo/$arch/bar/$basearch"),
+                    "http://foo/i686/bar/i386");
 }
 
 test_suite*
index bf5baa9..f68dded 100644 (file)
@@ -186,7 +186,10 @@ namespace zypp
   { return _pimpl->alias; }
 
   std::string RepoInfo::name() const
-  { return _pimpl->name; }
+  {
+    repo::RepoVariablesStringReplacer replacer;
+    return replacer(_pimpl->name);
+  }
 
   Pathname RepoInfo::filepath() const
   { return _pimpl->filepath; }
@@ -204,7 +207,19 @@ namespace zypp
   { return _pimpl->gpgkey_url; }
 
   std::set<Url> RepoInfo::baseUrls() const
-  { return _pimpl->baseUrls; }
+  {
+    RepoInfo::url_set replaced_urls;
+    repo::RepoVariablesUrlReplacer replacer;
+    for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
+          it != _pimpl->baseUrls.end();
+          ++it )
+    {
+      replaced_urls.insert(replacer(*it));
+    }
+    return replaced_urls;
+
+    return _pimpl->baseUrls;
+  }
 
   Pathname RepoInfo::path() const
   { return _pimpl->path; }
@@ -233,9 +248,8 @@ namespace zypp
   {
     str << "--------------------------------------" << std::endl;
     str << "- alias       : " << alias() << std::endl;
-    std::set<Url> url_set(baseUrls());
-    for ( std::set<Url>::const_iterator it = url_set.begin();
-          it != url_set.end();
+    for ( urls_const_iterator it = baseUrlsBegin();
+          it != baseUrlsEnd();
           ++it )
     {
       str << "- url         : " << *it << std::endl;
@@ -253,23 +267,24 @@ namespace zypp
 
   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
   {
+    // we save the original data without variable replacement
     str << "[" << alias() << "]" << endl;
-    str << "name=" << name() << endl;
+    str << "name=" << _pimpl->name << endl;
 
-    if ( ! baseUrls().empty() )
+    if ( ! _pimpl->baseUrls.empty() )
       str << "baseurl=";
-    for ( urls_const_iterator it = baseUrlsBegin();
-          it != baseUrlsEnd();
+    for ( url_set::const_iterator it = _pimpl->baseUrls.begin();
+          it != _pimpl->baseUrls.end();
           ++it )
     {
       str << *it << endl;
     }
 
-    if ( ! path().empty() )
+    if ( ! _pimpl->path.empty() )
       str << "path="<< path() << endl;
 
-    if ( ! (mirrorListUrl().asString().empty()) )
-      str << "mirrorlist=" << mirrorListUrl() << endl;
+    if ( ! (_pimpl->mirrorlist_url.asString().empty()) )
+      str << "mirrorlist=" << _pimpl->mirrorlist_url << endl;
 
     str << "type=" << type().asString() << endl;
     str << "enabled=" << (enabled() ? "1" : "0") << endl;
index 7c06ff9..4de790a 100644 (file)
@@ -17,6 +17,7 @@
 #include <set>
 #include "zypp/base/PtrTypes.h"
 #include "zypp/base/Iterator.h"
+#include "zypp/base/Deprecated.h"
 
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
@@ -88,7 +89,7 @@ namespace zypp
      *
      * \deprecated IMO superfluous as we provide begin/end iterator.
      */
-    std::set<Url> baseUrls() const;
+    ZYPP_DEPRECATED std::set<Url> baseUrls() const;
 
     /**
      * \short Repository path
index c91dba9..5e639f8 100644 (file)
@@ -170,7 +170,7 @@ namespace zypp
 
   static void assert_urls( const RepoInfo &info )
   {
-    if (info.baseUrls().empty())
+    if (info.baseUrlsEmpty())
         ZYPP_THROW(RepoNoUrlException());
   }
 
index 633518f..a2de3fb 100644 (file)
@@ -90,10 +90,10 @@ namespace zypp
       Url url;
       RepoInfo info = _package->repository().info();
       // FIXME we only support the first url for now.
-      if ( info.baseUrls().empty() )
+      if ( info.baseUrlsEmpty() )
         ZYPP_THROW(Exception("No url in repository."));
       else
-        url = * info.baseUrls().begin();
+        url = * info.baseUrlsBegin();
 
       MIL << "provide Package " << _package << endl;
       ScopedGuard guardReport( newReport() );
@@ -125,10 +125,10 @@ namespace zypp
       Url url;
       RepoInfo info = _package->repository().info();
       // FIXME we only support the first url for now.
-      if ( info.baseUrls().empty() )
+      if ( info.baseUrlsEmpty() )
         ZYPP_THROW(Exception("No url in repository."));
       else
-        url = * info.baseUrls().begin();
+        url = * info.baseUrlsBegin();
 
       // check whether to process patch/delta rpms
       if ( MediaManager::downloads(url) )
index 445d32c..4e8cb23 100644 (file)
@@ -62,9 +62,22 @@ std::string RepoVariablesStringReplacer::operator()( const std::string &value )
                    "$arch",
                    ZConfig::instance().systemArchitecture().asString() );
   // $basearch
-  ZConfig::instance().systemArchitecture();
   
-  ZConfig::instance();
+  Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
+  Arch::CompatSet::const_iterator it = cset.end();
+  --it;
+  // now at noarch
+  --it;
+  
+  Arch basearch = *it;
+  if ( basearch == Arch_noarch )
+  {
+    basearch = ZConfig::instance().systemArchitecture();
+  }
+
+  newvalue = gsub( newvalue,
+                   "$basearch",
+                   basearch.asString() );
   return newvalue;
 }