Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Capability.cc
index dd4c3c6..3147c8a 100644 (file)
@@ -134,7 +134,7 @@ namespace zypp
 
     /** Build \ref Capability from data. No parsing required.
     */
-    sat::detail::IdType relFromStr( ::_Pool * pool_r,
+    sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
                                     const Arch & arch_r,
                                     const std::string & name_r,
                                     Rel op_r,
@@ -148,20 +148,20 @@ namespace zypp
       if ( split.kind() == ResKind::srcpackage )
       {
         // map 'kind srcpackage' to 'arch src', the pseudo architecture
-        // satsolver uses.
-        nid = ::rel2id( pool_r, nid, IdString(ARCH_SRC).id(), REL_ARCH, /*create*/true );
+        // libsolv uses.
+        nid = ::pool_rel2id( pool_r, nid, IdString(ARCH_SRC).id(), REL_ARCH, /*create*/true );
       }
 
       // Extend name by architecture, if provided and not a srcpackage
       if ( ! arch_r.empty() && kind_r != ResKind::srcpackage )
       {
-        nid = ::rel2id( pool_r, nid, arch_r.id(), REL_ARCH, /*create*/true );
+        nid = ::pool_rel2id( pool_r, nid, arch_r.id(), REL_ARCH, /*create*/true );
       }
 
       // Extend 'op edition', if provided
       if ( op_r != Rel::ANY && ed_r != Edition::noedition )
       {
-        nid = ::rel2id( pool_r, nid, ed_r.id(), op_r.bits(), /*create*/true );
+        nid = ::pool_rel2id( pool_r, nid, ed_r.id(), op_r.bits(), /*create*/true );
       }
 
       return nid;
@@ -170,7 +170,7 @@ namespace zypp
    /** Build \ref Capability from data, just parsing name for '[.arch]' and detect
     * 'kind srcpackage' (will be mapped to arch \c src).
     */
-    sat::detail::IdType relFromStr( ::_Pool * pool_r,
+    sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
                                     const std::string & name_r, Rel op_r, const Edition & ed_r,
                                     const ResKind & kind_r )
     {
@@ -202,7 +202,7 @@ namespace zypp
 
     /** Full parse from string, unless Capability::PARSED.
     */
-    sat::detail::IdType relFromStr( ::_Pool * pool_r,
+    sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
                                     const Arch & arch_r, // parse from name if empty
                                     const std::string & str_r, const ResKind & kind_r,
                                     Capability::CtorFlag flag_r )
@@ -299,8 +299,17 @@ namespace zypp
   : _id( relFromStr( myPool().getPool(), arch_r, name_r, op_r, ed_r, prefix_r ) )
   {}
 
+  ///////////////////////////////////////////////////////////////////
+  // Ctor creating a namespace: capability.
+  ///////////////////////////////////////////////////////////////////
+
+  Capability::Capability( ResolverNamespace namespace_r, IdString value_r )
+  : _id( ::pool_rel2id( myPool().getPool(), asIdString(namespace_r).id(), (value_r.empty() ? STRID_NULL : value_r.id() ), REL_NAMESPACE, /*create*/true ) )
+  {}
+
+
   const char * Capability::c_str() const
-  { return( _id ? ::dep2str( myPool().getPool(), _id ) : "" ); }
+  { return( _id ? ::pool_dep2str( myPool().getPool(), _id ) : "" ); }
 
   CapMatch Capability::_doMatch( sat::detail::IdType lhs,  sat::detail::IdType rhs )
   {
@@ -360,19 +369,21 @@ namespace zypp
     static       str::smatch what;
     static const str::regex  filenameRegex(
                  "/(s?bin|lib(64)?|etc)/|^/usr/(games/|share/(dict/words|magic\\.mime)$)|^/opt/gnome/games/",
-                 str::regex::optimize|str::regex::nosubs );
+                 str::regex::nosubs );
 
     return str::regex_match( name_r, what, filenameRegex );
   }
 
-  Capability Capability::guessPackageSpec( const std::string & str_r )
+  Capability Capability::guessPackageSpec( const std::string & str_r, bool & rewrote_r )
   {
     Capability cap( str_r );
     CapDetail detail( cap.detail() );
 
     // str_r might be the form "libzypp-1.2.3-4.5(.arch)'
     // correctly parsed as name capability by the ctor.
-    if ( detail.isNamed() && ::strrchr( detail.name().c_str(), '-' ) && sat::WhatProvides( cap ).empty() )
+    // TODO: Think about allowing glob char in name - for now don't process
+    if ( detail.isNamed() && !::strpbrk( detail.name().c_str(), "*?[{" )
+      && ::strrchr( detail.name().c_str(), '-' ) && sat::WhatProvides( cap ).empty() )
     {
       Arch origArch( detail.arch() ); // to support a trailing .arch
 
@@ -386,7 +397,10 @@ namespace zypp
       ResPool pool( ResPool::instance() );
       // require name part matching a pool items name (not just provides!)
       if ( pool.byIdentBegin( detail.name() ) != pool.byIdentEnd( detail.name() ) )
+      {
+       rewrote_r = true;
        return guesscap;
+      }
 
       // try the one but last '-'
       if ( pos )
@@ -401,13 +415,24 @@ namespace zypp
 
           // require name part matching a pool items name (not just provides!)
           if ( pool.byIdentBegin( detail.name() ) != pool.byIdentEnd( detail.name() ) )
+         {
+           rewrote_r = true;
            return guesscap;
+         }
         }
       }
     }
+
+    rewrote_r = false;
     return cap;
   }
 
+  Capability Capability::guessPackageSpec( const std::string & str_r )
+  {
+    bool dummy;
+    return guessPackageSpec( str_r, dummy );
+  }
+
   /******************************************************************
   **
   **   FUNCTION NAME : operator<<
@@ -473,7 +498,7 @@ namespace zypp
       _kind = EXPRESSION;
       return;
     }
-    // map back satsolvers pseudo arch 'src' to kind srcpackage
+    // map back libsolvs pseudo arch 'src' to kind srcpackage
     if ( _archIfSimple == ARCH_SRC )
     {
       _lhs = IdString( (ResKind::srcpackage.asString() + ":" + IdString(_lhs).c_str()).c_str() ).id();