Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / zypp_detail / ZYppImpl.cc
index 96afdfd..8af290a 100644 (file)
 #include "zypp/base/String.h"
 
 #include "zypp/zypp_detail/ZYppImpl.h"
-#include "zypp/solver/detail/Helper.h"
 #include "zypp/target/TargetImpl.h"
 #include "zypp/ZYpp.h"
-#include "zypp/NVRAD.h"
 #include "zypp/DiskUsageCounter.h"
-#include "zypp/NameKindProxy.h"
-#include "zypp/Locks.h"
+#include "zypp/ZConfig.h"
+#include "zypp/sat/Pool.h"
+#include "zypp/PoolItem.h"
+
+#include "zypp/ZYppCallbacks.h"        // JobReport::instance
 
 using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  namespace media
+  {
+    ScopedDisableMediaChangeReport::ScopedDisableMediaChangeReport( bool condition_r )
+    {
+      static weak_ptr<callback::TempConnect<media::MediaChangeReport> > globalguard;
+      if ( condition_r && ! (_guard = globalguard.lock()) )
+      {
+       // aquire a new one....
+       _guard.reset( new callback::TempConnect<media::MediaChangeReport>() );
+       globalguard = _guard;
+      }
+    }
+  } // namespace media
+  ///////////////////////////////////////////////////////////////////
+
+  callback::SendReport<JobReport> & JobReport::instance()
+  {
+    static callback::SendReport<JobReport> _report;
+    return _report;
+  }
+
+
   ///////////////////////////////////////////////////////////////////
   namespace zypp_detail
   { /////////////////////////////////////////////////////////////////
@@ -42,8 +67,8 @@ namespace zypp
     : _target(0)
     , _resolver( new Resolver( ResPool::instance()) )
     {
+      ZConfig::instance().about( MIL );
       MIL << "Initializing keyring..." << std::endl;
-      //_keyring = new KeyRing(homePath() + Pathname("/keyring/all"), homePath() + Pathname("/keyring/trusted"));
       _keyring = new KeyRing(tmpPath());
     }
 
@@ -91,29 +116,27 @@ namespace zypp
       return _target;
      }
 
-    void ZYppImpl::initializeTarget(const Pathname & root)
+    void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
     {
-      MIL << "initTarget( " << root << endl;
+      MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
       if (_target) {
-       if (_target->root() == root) {
-           MIL << "Repeated call to initializeTarget()" << endl;
-           return;
-       }
-#warning NEED SOME NEW WAY TO INDICATE NEDD OF TARGET RELOAD
-#if 0
-       removeInstalledResolvables( );
-#endif
+          if (_target->root() == root) {
+              MIL << "Repeated call to initializeTarget()" << endl;
+              return;
+          }
+
+          _target->unload();
+
       }
-      _target = new Target( root );
+      _target = new Target( root, doRebuild_r );
+      _target->buildCache();
     }
 
     void ZYppImpl::finishTarget()
     {
-#warning NEED SOME NEW WAY TO UNLOAD THE POOL
-#if 0
       if (_target)
-       removeInstalledResolvables();
-#endif
+          _target->unload();
+
       _target = 0;
     }
 
@@ -124,6 +147,8 @@ namespace zypp
      * and target used for transact. */
     ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
     {
+      setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
+
       if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
       {
         ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
@@ -135,20 +160,19 @@ namespace zypp
 
       ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
 
-      if (! policy_r.dryRun() ) {
-        // Tag target data invalid, so they are reloaded on the next call to
-        // target->resolvables(). Actually the target should do this without
-        // foreign help.
-        _target->reset();
-#warning NEED SOME NEW WAY TO INDICATE NEDD OF TARGET RELOAD
-#if 0
-       removeInstalledResolvables();
+      if (! policy_r.dryRun() )
+      {
         if ( policy_r.syncPoolAfterCommit() )
           {
             // reload new status from target
-            addResolvables( _target->resolvables(), true );
+            DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
+            _target->load();
+          }
+        else
+          {
+            DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
+            _target->unload();
           }
-#endif
       }
 
       MIL << "Commit (" << policy_r << ") returned: "
@@ -163,111 +187,11 @@ namespace zypp
       _target->_pimpl->installSrcPackage( srcPackage_r );
     }
 
-    //------------------------------------------------------------------------
-    // locales
-
-    /** */
-    void ZYppImpl::setRequestedLocales( const LocaleSet & locales_r )
-    {
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-     ResPool mpool( ResPool::instance() );
-      // assert all requested are available
-      for ( LocaleSet::const_iterator it = locales_r.begin();
-            it != locales_r.end(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, it->code() ) );
-          if ( select.installedEmpty() && select.availableEmpty() )
-            _pool.insert( Language::availableInstance( *it ) );
-        }
-
-      // now adjust status
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, (*it)->name() ) );
-          if ( locales_r.find( Locale( (*it)->name() ) ) != locales_r.end() )
-            {
-              // Language is requested
-              if ( select.installedEmpty() )
-                {
-                  if ( select.availableEmpty() )
-                    {
-                      // no item ==> provide available to install
-                      _pool.insert( Language::availableInstance( Locale((*it)->name()) ) );
-                      select = nameKindProxy<Language>( mpool, (*it)->name() );
-                    }
-                  // available only ==> to install
-                  select.availableBegin()->status().setTransactValue( ResStatus::TRANSACT, ResStatus::USER );
-                }
-              else
-                {
-                  // installed ==> keep it
-                  select.installedBegin()->status().setTransactValue( ResStatus::KEEP_STATE, ResStatus::USER );
-                  if ( ! select.availableEmpty() )
-                    {
-                      // both items ==> keep
-                      select.availableBegin()->status().resetTransact( ResStatus::USER );
-                    }
-                }
-            }
-          else
-            {
-              // Language is NOT requested
-              if ( ! select.installedEmpty() )
-                select.installedBegin()->status().setTransactValue( ResStatus::TRANSACT, ResStatus::USER );
-              if ( ! select.availableEmpty() )
-                select.availableBegin()->status().resetTransact( ResStatus::USER );
-            }
-        }
-#endif
-    }
-
-    /** */
-    ZYppImpl::LocaleSet ZYppImpl::getAvailableLocales() const
-    {
-      ZYpp::LocaleSet ret;
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-      ResPool mpool( ResPool::instance() );
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          if ( (*it).status().isUninstalled() ) // available!
-            ret.insert( Locale( (*it)->name() ) );
-        }
-#endif
-      return ret;
-    }
-
-    /** */
-    ZYppImpl::LocaleSet ZYppImpl::getRequestedLocales() const
+    ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
     {
-      ZYpp::LocaleSet ret;
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-     ResPool mpool( ResPool::instance() );
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, (*it)->name() ) );
-          if ( ! select.installedEmpty()
-               && select.installedBegin()->status().getTransactValue() != ResStatus::TRANSACT )
-            ret.insert( Locale( (*it)->name() ) );
-          else if ( ! select.availableEmpty()
-                    && select.availableBegin()->status().getTransactValue() == ResStatus::TRANSACT )
-            ret.insert( Locale( (*it)->name() ) );
-        }
-#endif
-      return ret;
-    }
-
-    void ZYppImpl::availableLocale( const Locale & locale_r )
-    {
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-      _pool.insert( Language::availableInstance( locale_r ) );
-#endif
+      if (! _target)
+        ZYPP_THROW( Exception("Target not initialized.") );
+      return _target->_pimpl->provideSrcPackage( srcPackage_r );
     }
 
     //------------------------------------------------------------------------
@@ -285,34 +209,6 @@ namespace zypp
       return zypp_tmp_dir.path();
     }
 
-    int ZYppImpl::applyLocks()
-    {
-      Pathname locksrcPath( "/etc/zypp/locks" );
-      try
-      {
-        Target_Ptr trg( target() );
-        if ( trg )
-          locksrcPath = trg->root() / locksrcPath;
-      }
-      catch ( ... )
-      {
-        // noop: Someone decided to let target() throw if the ptr is NULL ;(
-      }
-
-      int num=0;
-      PathInfo locksrc( locksrcPath );
-      if ( locksrc.isFile() )
-      {
-        MIL << "Reading locks from '" << locksrcPath << "'" << endl;
-        num = zypp::locks::readLocks( pool(), locksrcPath );
-        MIL << num << " items locked." << endl;
-      }
-      else
-      {
-        MIL << "No file '" << locksrcPath << "' to read locks from" << endl;
-      }
-      return num;
-    }
     /******************************************************************
      **
      **        FUNCTION NAME : operator<<