Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / zypp_detail / ZYppImpl.cc
index db8b79e..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
-  { /////////////////////////////////////////////////////////////////      
+  { /////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
     //
@@ -45,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());
     }
 
@@ -94,9 +116,9 @@ 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;
@@ -104,9 +126,9 @@ namespace zypp
           }
 
           _target->unload();
-  
+
       }
-      _target = new Target( root );
+      _target = new Target( root, doRebuild_r );
       _target->buildCache();
     }
 
@@ -114,7 +136,7 @@ namespace zypp
     {
       if (_target)
           _target->unload();
-      
+
       _target = 0;
     }
 
@@ -125,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.") );
@@ -136,18 +160,19 @@ namespace zypp
 
       ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
 
-      if (! policy_r.dryRun() ) {
-
-          DBG << "unloading " << sat::Pool::instance().systemRepoName() << " repo from pool" << endl;
-          
-        _target->unload();
-        
+      if (! policy_r.dryRun() )
+      {
         if ( policy_r.syncPoolAfterCommit() )
           {
             // reload new status from target
-            DBG << "reloading " << sat::Pool::instance().systemRepoName() << " repo to pool" << endl;
+            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();
+          }
       }
 
       MIL << "Commit (" << policy_r << ") returned: "
@@ -162,6 +187,13 @@ namespace zypp
       _target->_pimpl->installSrcPackage( srcPackage_r );
     }
 
+    ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
+    {
+      if (! _target)
+        ZYPP_THROW( Exception("Target not initialized.") );
+      return _target->_pimpl->provideSrcPackage( srcPackage_r );
+    }
+
     //------------------------------------------------------------------------
     // target store path
 
@@ -177,27 +209,6 @@ namespace zypp
       return zypp_tmp_dir.path();
     }
 
-    int ZYppImpl::applyLocks()
-    {
-      if (!ZConfig::instance().apply_locks_file())
-        return 0;
-
-      //TODO catch posibble exceptions
-      Locks::instance().loadLocks();
-
-      //current locks api doesn't support counting lock
-      //so count it after
-      int count = 0;
-      for_(it, sat::Pool::instance().solvablesBegin(),
-          sat::Pool::instance().solvablesEnd())
-      {
-        PoolItem i(*it);
-        if ( i.status().isLocked() )
-          count++;
-      }
-
-      return count;
-    }
     /******************************************************************
      **
      **        FUNCTION NAME : operator<<