Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / Product.cc
index b37d4c2..f195add 100644 (file)
@@ -79,20 +79,29 @@ namespace zypp
     // Look for a  provider of 'product(name) = version' of same
     // architecture and within the same repo.
     //
-    // bnc #497696: Update repos may have multiple release package versions
-    // providing the same product. As a workaround we link to the one with
-    // the highest version.
+    // Code12: Update repos may have multiple release package versions
+    // providing the same product. Prefer the one matching the buildtime,
+    // as the product buildtime is derived from the -release package.
     Capability identCap( str::form( "product(%s) = %s", name().c_str(), edition().c_str() ) );
 
     sat::Solvable found;
+    bool foundBuildTime = false;
     sat::WhatProvides providers( identCap );
     for_( it, providers.begin(), providers.end() )
     {
-      if ( it->repository() == repository()
-           && it->arch() == arch() )
+      if ( it->repository() == repository() && it->arch() == arch() )
       {
-        if ( ! found || found.edition() < it->edition() )
-          found = *it;
+       bool fitsBuildtime = ( PoolItem(*it)->buildtime() == buildtime() );
+       if ( found )
+       {
+         bool lowerEdition = ( it->edition() <= found.edition() );
+         if ( (  foundBuildTime && ( !fitsBuildtime || lowerEdition ) )
+           || ( !foundBuildTime && ( !fitsBuildtime && lowerEdition ) ) )
+           continue;
+       }
+       found = *it;
+       if ( fitsBuildtime )
+         foundBuildTime = true;
       }
     }
 
@@ -156,7 +165,12 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
 
   std::string Product::shortName() const
-  { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
+  {
+    std::string ret( lookupStrAttribute( sat::SolvAttr::productShortlabel ) );
+    if ( ret.empty() ) ret = name();
+    return ret;
+
+  }
 
   std::string Product::flavor() const
   {
@@ -197,6 +211,33 @@ namespace zypp
     return ret;
   }
 
+  Date Product::endOfLife() const
+  { return Date( lookupNumAttribute( sat::SolvAttr::productEndOfLife ) );}
+
+  std::vector<Repository::ContentIdentifier> Product::updateContentIdentifier() const
+  {
+    std::vector<Repository::ContentIdentifier> ret;
+    sat::LookupAttr q( sat::SolvAttr::productUpdatesRepoid, sat::SolvAttr::productUpdates, *this );
+    if ( ! q.empty() )
+    {
+      ret.reserve( 2 );
+      for_( it, q.begin(), q.end() )
+       ret.push_back( it.asString() );
+    }
+    return ret;
+  }
+
+  bool Product::hasUpdateContentIdentifier( const Repository::ContentIdentifier & cident_r ) const
+  {
+    sat::LookupAttr q( sat::SolvAttr::productUpdatesRepoid, sat::SolvAttr::productUpdates, *this );
+    for_( it, q.begin(), q.end() )
+    {
+      if ( it.asString() == cident_r )
+       return true;
+    }
+    return false;
+  }
+
   bool Product::isTargetDistribution() const
   { return isSystem() && lookupStrAttribute( sat::SolvAttr::productType ) == "base"; }
 
@@ -206,6 +247,9 @@ namespace zypp
   std::string Product::registerRelease() const
   { return lookupStrAttribute( sat::SolvAttr::productRegisterRelease ); }
 
+  std::string Product::registerFlavor() const
+  { return lookupStrAttribute( sat::SolvAttr::productRegisterFlavor ); }
+  
   /////////////////////////////////////////////////////////////////
 
   Product::UrlList Product::urls( const std::string & key_r ) const