Imported Upstream version 17.16.0
[platform/upstream/libzypp.git] / zypp / sat / Solvable.cc
index b5f0ede..e47c9f8 100644 (file)
@@ -141,10 +141,12 @@ namespace zypp
       else
       {
        for ( Locale l( lang_r ); l; l = l.fallback() )
+       {
          if ( (s = ::solvable_lookup_str_lang( _solvable, attr.id(), l.c_str(), 0 )) )
            return s;
-         // here: no matching locale, so use default
-         s = ::solvable_lookup_str_lang( _solvable, attr.id(), 0, 0 );
+       }
+       // here: no matching locale, so use default
+       s = ::solvable_lookup_str_lang( _solvable, attr.id(), 0, 0 );
       }
       return s ? s : std::string();
    }
@@ -375,6 +377,22 @@ namespace zypp
       return isSystem() && myPool().isOnSystemByUser( ident() );
     }
 
+    bool Solvable::onSystemByAuto() const
+    {
+      return isSystem() && myPool().isOnSystemByAuto( ident() );
+    }
+
+    bool Solvable::identIsAutoInstalled( const IdString & ident_r )
+    {
+      return myPool().isOnSystemByAuto( ident_r );
+    }
+
+    bool Solvable::isNeedreboot() const
+    {
+      NO_SOLVABLE_RETURN( false );
+      return myPool().isNeedreboot( *this );
+    }
+
     bool Solvable::multiversionInstall() const
     {
       NO_SOLVABLE_RETURN( false );
@@ -510,10 +528,22 @@ namespace zypp
       return ret;
     }
 
+    std::pair<bool, CapabilitySet> Solvable::matchesSolvable(const SolvAttr &attr, const Solvable &solv) const
+    {
+      sat::Queue capQueue;
+      int res = solvable_matchessolvable( get(), attr.id(), static_cast<Id>( solv.id() ), capQueue, 0 );
+
+      CapabilitySet caps;
+      if ( capQueue.size() )
+        std::for_each( capQueue.begin(), capQueue.end(), [ &caps ]( auto cap ){ caps.insert( Capability(cap) );});
+
+      return std::make_pair( res == 1, std::move(caps) );
+    }
+
     ///////////////////////////////////////////////////////////////////
     namespace
     {
-      /** Expand \ref Capability and call \c fnc_r for each namescpace:language
+      /** Expand \ref Capability and call \c fnc_r for each namespace:language
        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
        * false to indicate abort.
        */
@@ -554,7 +584,7 @@ namespace zypp
         return 0;
       }
 
-       /** Expand \ref Capability and call \c fnc_r for each namescpace:language
+       /** Expand \ref Capability and call \c fnc_r for each namespace:language
        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
        * false to indicate abort.
        */
@@ -626,7 +656,14 @@ namespace zypp
     unsigned Solvable::mediaNr() const
     {
       NO_SOLVABLE_RETURN( 0U );
-      return lookupNumAttribute( SolvAttr::medianr );
+      // medianumber and path
+      unsigned medianr = 0U;
+      const char * file = ::solvable_lookup_location( _solvable, &medianr );
+      if ( ! file )
+        medianr = 0U;
+      else if ( ! medianr )
+       medianr = 1U;
+      return medianr;
     }
 
     ByteCount Solvable::installSize() const
@@ -678,8 +715,12 @@ namespace zypp
       if ( ret.empty() && isKind<Product>() )
       {
        const RepoInfo & ri( repoInfo() );
-       if ( ri.needToAcceptLicense() || ! ui::Selectable::get( *this )->hasInstalledObj() )
-         ret = ri.getLicense( lang_r ); // bnc#908976: suppress informal license upon update
+       std::string riname( name() );   // "license-"+name with fallback "license"
+       if ( ! ri.hasLicense( riname ) )
+         riname.clear();
+
+       if ( ri.needToAcceptLicense( riname ) || ! ui::Selectable::get( *this )->hasInstalledObj() )
+         ret = ri.getLicense( riname, lang_r ); // bnc#908976: suppress informal license upon update
       }
       return ret;
     }
@@ -687,7 +728,16 @@ namespace zypp
     bool Solvable::needToAcceptLicense() const
     {
       NO_SOLVABLE_RETURN( false );
-      return ( isKind<Product>() ? repoInfo().needToAcceptLicense() : true );
+      if ( isKind<Product>() )
+      {
+       const RepoInfo & ri( repoInfo() );
+       std::string riname( name() );   // "license-"+name with fallback "license"
+       if ( ! ri.hasLicense( riname ) )
+         riname.clear();
+
+       return ri.needToAcceptLicense( riname );
+      }
+      return true;
     }