Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / sat / detail / PoolImpl.cc
index 68f9d33..eb77b4e 100644 (file)
@@ -10,6 +10,7 @@
  *
 */
 #include <iostream>
+#include <fstream>
 #include <boost/mpl/int.hpp>
 
 #include "zypp/base/Easy.h"
@@ -19,6 +20,7 @@
 #include "zypp/base/Measure.h"
 #include "zypp/base/WatchFile.h"
 #include "zypp/base/Sysconfig.h"
+#include "zypp/base/IOStream.h"
 
 #include "zypp/ZConfig.h"
 
 
 extern "C"
 {
-// Workaround satsolver project not providing a common include
+// Workaround libsolv project not providing a common include
 // directory. (the -devel package does, but the git repo doesn't).
-// #include <satsolver/repo_helix.h>
-void repo_add_helix( ::Repo *repo, FILE *fp, int flags );
+// #include <solv/repo_helix.h>
+int repo_add_helix( ::Repo *repo, FILE *fp, int flags );
 }
 
 using std::endl;
@@ -46,7 +48,17 @@ using std::endl;
 
 // ///////////////////////////////////////////////////////////////////
 namespace zypp
-{ /////////////////////////////////////////////////////////////////
+{
+  /////////////////////////////////////////////////////////////////
+  namespace env
+  {
+    /**  */
+    inline int LIBSOLV_DEBUGMASK()
+    {
+      const char * envp = getenv("LIBSOLV_DEBUGMASK");
+      return envp ? str::strtonum<int>( envp ) : 0;
+    }
+  } // namespace env
   ///////////////////////////////////////////////////////////////////
   namespace sat
   { /////////////////////////////////////////////////////////////////
@@ -80,16 +92,23 @@ namespace zypp
         return _val;
       }
 
+      const Pathname & sysconfigStoragePath()
+      {
+       static const Pathname _val( "/etc/sysconfig/storage" );
+       return _val;
+      }
+
+
       /////////////////////////////////////////////////////////////////
 
       static void logSat( struct _Pool *, void *data, int type, const char *logString )
       {
-         if ( type & (SAT_FATAL|SAT_ERROR) ) {
-           _ERR("satsolver") << logString;
-         } else if ( type & SAT_DEBUG_STATS ) {
-           _DBG("satsolver") << logString;
+         if ( type & (SOLV_FATAL|SOLV_ERROR) ) {
+           _ERR("libsolv") << logString;
+         } else if ( type & SOLV_DEBUG_STATS ) {
+           _DBG("libsolv") << logString;
          } else {
-           _MIL("satsolver") << logString;
+           _MIL("libsolv") << logString;
          }
       }
 
@@ -129,26 +148,11 @@ namespace zypp
 
           case NAMESPACE_FILESYSTEM:
           {
-            static const Pathname sysconfigStoragePath( "/etc/sysconfig/storage" );
-            static WatchFile      sysconfigFile( sysconfigStoragePath, WatchFile::NO_INIT );
-            static std::set<std::string> requiredFilesystems;
-            if ( sysconfigFile.hasChanged() )
-            {
-              requiredFilesystems.clear();
-              str::split( base::sysconfig::read( sysconfigStoragePath )["USED_FS_LIST"],
-                          std::inserter( requiredFilesystems, requiredFilesystems.end() ) );
-            }
+           const std::set<std::string> & requiredFilesystems( reinterpret_cast<PoolImpl*>(data)->requiredFilesystems() );
             return requiredFilesystems.find( IdString(rhs).asString() ) != requiredFilesystems.end() ? RET_systemProperty : RET_unsupported;
           }
           break;
 
-          case NAMESPACE_PRODUCTBUDDY:
-          {
-            PoolItem pi( (Solvable(rhs)) );
-            return( pi ? pi.buddy().id() : noId );
-          }
-
-          break;
         }
 
         WAR << "Unhandled " << Capability( lhs ) << " vs. " << Capability( rhs ) << endl;
@@ -179,12 +183,23 @@ namespace zypp
         {
           ZYPP_THROW( Exception( _("Can not create sat-pool.") ) );
         }
+        // by now we support only a RPM backend
+        ::pool_setdisttype(_pool, DISTTYPE_RPM );
+
         // initialialize logging
-        bool verbose = ( getenv("ZYPP_FULLLOG") || getenv("ZYPP_LIBSAT_FULLLOG") );
-       if (verbose)
-           ::pool_setdebuglevel( _pool, 2 );
+       if ( env::LIBSOLV_DEBUGMASK() )
+       {
+         ::pool_setdebugmask(_pool, env::LIBSOLV_DEBUGMASK() );
+       }
        else
-           ::pool_setdebugmask(_pool, SAT_DEBUG_JOB|SAT_DEBUG_STATS);
+       {
+         if ( getenv("ZYPP_LIBSOLV_FULLLOG") || getenv("ZYPP_LIBSAT_FULLLOG") )
+           ::pool_setdebuglevel( _pool, 3 );
+         else if ( getenv("ZYPP_FULLLOG") )
+           ::pool_setdebuglevel( _pool, 2 );
+         else
+           ::pool_setdebugmask(_pool, SOLV_DEBUG_JOB|SOLV_DEBUG_STATS );
+       }
 
         ::pool_setdebugcallback( _pool, logSat, NULL );
 
@@ -234,7 +249,7 @@ namespace zypp
 
       void PoolImpl::prepare() const
       {
-        if ( _watcher.remember( _serial ) )
+       if ( _watcher.remember( _serial ) )
         {
           // After repo/solvable add/remove:
           // set pool architecture
@@ -243,27 +258,30 @@ namespace zypp
         if ( ! _pool->whatprovides )
         {
           MIL << "pool_createwhatprovides..." << endl;
+
           ::pool_addfileprovides( _pool );
           ::pool_createwhatprovides( _pool );
         }
         if ( ! _pool->languages )
         {
-          std::vector<std::string> fallbacklist;
-          for ( Locale l( ZConfig::instance().textLocale() ); l != Locale::noCode; l = l.fallback() )
-          {
-            fallbacklist.push_back( l.code() );
-          }
-          dumpRangeLine( MIL << "pool_set_languages: ", fallbacklist.begin(), fallbacklist.end() ) << endl;
-
-          std::vector<const char *> fallbacklist_cstr;
-          for_( it, fallbacklist.begin(), fallbacklist.end() )
-          {
-            fallbacklist_cstr.push_back( it->c_str() );
-          }
-          ::pool_set_languages( _pool, &fallbacklist_cstr.front(), fallbacklist_cstr.size() );
+         // initial seting
+         const_cast<PoolImpl*>(this)->setTextLocale( ZConfig::instance().textLocale() );
         }
       }
 
+      void PoolImpl::prepareForSolving() const
+      {
+       // additional /etc/sysconfig/storage check:
+       static WatchFile sysconfigFile( sysconfigStoragePath(), WatchFile::NO_INIT );
+       if ( sysconfigFile.hasChanged() )
+       {
+         _requiredFilesystemsPtr.reset(); // recreated on demand
+         const_cast<PoolImpl*>(this)->depSetDirty( "/etc/sysconfig/storage change" );
+       }
+       // finally prepare as usual:
+       prepare();
+      }
+
       ///////////////////////////////////////////////////////////////////
 
       ::_Repo * PoolImpl::_createRepo( const std::string & name_r )
@@ -278,14 +296,16 @@ namespace zypp
       void PoolImpl::_deleteRepo( ::_Repo * repo_r )
       {
         setDirty(__FUNCTION__, repo_r->name );
-        ::repo_free( repo_r, /*reuseids*/false );
+       if ( isSystemRepo( repo_r ) )
+         _autoinstalled.clear();
         eraseRepoInfo( repo_r );
+        ::repo_free( repo_r, /*reuseids*/false );
       }
 
       int PoolImpl::_addSolv( ::_Repo * repo_r, FILE * file_r )
       {
         setDirty(__FUNCTION__, repo_r->name );
-        int ret = ::repo_add_solv( repo_r , file_r );
+        int ret = ::repo_add_solv( repo_r, file_r, 0 );
         if ( ret == 0 )
           _postRepoAdd( repo_r );
         return ret;
@@ -294,8 +314,9 @@ namespace zypp
       int PoolImpl::_addHelix( ::_Repo * repo_r, FILE * file_r )
       {
         setDirty(__FUNCTION__, repo_r->name );
-        ::repo_add_helix( repo_r , file_r, 0 ); // unfortunately void
-        _postRepoAdd( repo_r );
+        int ret = ::repo_add_helix( repo_r, file_r, 0 );
+        if ( ret == 0 )
+          _postRepoAdd( repo_r );
         return 0;
       }
 
@@ -310,7 +331,7 @@ namespace zypp
             for_( it, sysarchs.begin(), sysarchs.end() )
               sysids.insert( it->id() );
 
-              // unfortunately satsolver treats src/nosrc as architecture:
+              // unfortunately libsolv treats src/nosrc as architecture:
             sysids.insert( ARCH_SRC );
             sysids.insert( ARCH_NOSRC );
           }
@@ -356,7 +377,7 @@ namespace zypp
         {
           bool dirty = false;
 
-          // satsolver priority is based on '<', while yum's repoinfo
+          // libsolv priority is based on '<', while yum's repoinfo
           // uses 1(highest)->99(lowest). Thus we use -info_r.priority.
           if ( repo->priority != int(-info_r.priority()) )
           {
@@ -394,6 +415,23 @@ namespace zypp
         MIL << "New Solver Locales: " << locale2Solver << endl;
       }
 
+      void PoolImpl::setTextLocale( const Locale & locale_r )
+      {
+       std::vector<std::string> fallbacklist;
+       for ( Locale l( locale_r ); l != Locale::noCode; l = l.fallback() )
+       {
+         fallbacklist.push_back( l.code() );
+       }
+       dumpRangeLine( MIL << "pool_set_languages: ", fallbacklist.begin(), fallbacklist.end() ) << endl;
+
+       std::vector<const char *> fallbacklist_cstr;
+       for_( it, fallbacklist.begin(), fallbacklist.end() )
+       {
+         fallbacklist_cstr.push_back( it->c_str() );
+       }
+       ::pool_set_languages( _pool, &fallbacklist_cstr.front(), fallbacklist_cstr.size() );
+      }
+
       void PoolImpl::setRequestedLocales( const LocaleSet & locales_r )
       {
         depSetDirty( "setRequestedLocales" );
@@ -512,6 +550,18 @@ namespace zypp
         }
       }
 
+      const std::set<std::string> & PoolImpl::requiredFilesystems() const
+      {
+       if ( ! _requiredFilesystemsPtr )
+       {
+         _requiredFilesystemsPtr.reset( new std::set<std::string> );
+         std::set<std::string> & requiredFilesystems( *_requiredFilesystemsPtr );
+         str::split( base::sysconfig::read( sysconfigStoragePath() )["USED_FS_LIST"],
+                     std::inserter( requiredFilesystems, requiredFilesystems.end() ) );
+       }
+       return *_requiredFilesystemsPtr;
+      }
+
       /////////////////////////////////////////////////////////////////
     } // namespace detail
     ///////////////////////////////////////////////////////////////////