Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / devel / devel.ma / NewPool.cc
index 55ea2dd..a8cf123 100644 (file)
@@ -1,41 +1,55 @@
 #include "Tools.h"
 
+#include "zypp/PoolQueryResult.h"
+
 #include <zypp/base/PtrTypes.h>
 #include <zypp/base/Exception.h>
 #include <zypp/base/Gettext.h>
 #include <zypp/base/LogTools.h>
 #include <zypp/base/Debug.h>
+#include <zypp/base/Functional.h>
+#include <zypp/base/IOStream.h>
+#include <zypp/base/InputStream.h>
 #include <zypp/base/ProvideNumericId.h>
+#include <zypp/base/Flags.h>
 #include <zypp/AutoDispose.h>
 
 #include "zypp/ResPoolProxy.h"
 
 #include "zypp/ZYppCallbacks.h"
-#include "zypp/NVRAD.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResFilters.h"
-#include "zypp/CapFilters.h"
 #include "zypp/ResObjects.h"
 #include "zypp/Digest.h"
 #include "zypp/PackageKeyword.h"
+#include "zypp/TmpPath.h"
 #include "zypp/ManagedFile.h"
-#include "zypp/NameKindProxy.h"
-#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/MediaSetAccess.h"
+
 
 #include "zypp/RepoManager.h"
+#include "zypp/Repository.h"
 #include "zypp/RepoInfo.h"
-
+#include "zypp/TriBool.h"
 #include "zypp/repo/PackageProvider.h"
 
-#include "zypp/ui/PatchContents.h"
 #include "zypp/ResPoolProxy.h"
 
 #include "zypp/sat/Pool.h"
-#include "zypp/sat/Repo.h"
-#include "zypp/sat/Solvable.h"
+#include "zypp/sat/LocaleSupport.h"
+#include "zypp/sat/LookupAttr.h"
+#include "zypp/sat/AttrMatcher.h"
+#include "zypp/sat/SolvableSet.h"
+#include "zypp/sat/SolvIterMixin.h"
 #include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/sat/WhatObsoletes.h"
+#include "zypp/PoolQuery.h"
+#include "zypp/ServiceInfo.h"
+#include "zypp/media/MediaPriority.h"
 
-#include <zypp/base/GzStream.h>
+#include "zypp/target/rpm/RpmDb.h"
+#include "zypp/target/rpm/RpmHeader.h"
+#include "zypp/target/rpm/librpmDb.h"
 
 #include <boost/mpl/int.hpp>
 
@@ -46,7 +60,7 @@ using namespace zypp::ui;
 
 ///////////////////////////////////////////////////////////////////
 
-static const Pathname sysRoot( "/Local/ROOT" );
+static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
@@ -117,15 +131,15 @@ namespace zypp
 
 void dbgDu( Selectable::Ptr sel )
 {
-  if ( sel->installedPoolItem() )
+  if ( sel->installedObj() )
   {
-    DBG << "i: " << sel->installedPoolItem() << endl
-        << sel->installedPoolItem()->diskusage() << endl;
+    DBG << "i: " << sel->installedObj() << endl
+        << sel->installedObj()->diskusage() << endl;
   }
-  if ( sel->candidatePoolItem() )
+  if ( sel->candidateObj() )
   {
-    DBG << "c: " << sel->candidatePoolItem() << endl
-        << sel->candidatePoolItem()->diskusage() << endl;
+    DBG << "c: " << sel->candidateObj() << endl
+        << sel->candidateObj()->diskusage() << endl;
   }
   INT << sel << endl
       << getZYpp()->diskUsage() << endl;
@@ -133,19 +147,46 @@ void dbgDu( Selectable::Ptr sel )
 
 ///////////////////////////////////////////////////////////////////
 
+std::ostream & testDump( std::ostream & str, const PoolItem & pi )
+{
+  str << pi << endl;
+  Package::constPtr p( asKind<Package>(pi) );
+  if ( p )
+  {
+#define OUTS(V) str << str::form("%-25s: ",#V) << p->V() << endl
+    Locale l( "de" );
+    str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
+    l = Locale( "fr" );
+    str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
+    l = Locale( "dsdf" );
+    str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
+    OUTS( summary );
+    OUTS( installSize );
+    OUTS( downloadSize );
+    OUTS( sourcePkgName );
+    OUTS( sourcePkgEdition );
+    OUTS( checksum );
+    OUTS( location );
+#undef OUTS
+
+
+  }
+  return str;
+}
+
 struct Xprint
 {
   bool operator()( const PoolItem & obj_r )
   {
-    MIL << obj_r << endl;
-    DBG << " -> " << obj_r->satSolvable() << endl;
+    //MIL << obj_r << endl;
+    //DBG << " -> " << obj_r->satSolvable() << endl;
 
     return true;
   }
 
   bool operator()( const sat::Solvable & obj_r )
   {
-    dumpOn( MIL, obj_r ) << endl;
+    //dumpOn( MIL, obj_r ) << endl;
     return true;
   }
 };
@@ -184,35 +225,13 @@ struct StatusInstall : public SetTransactValue
   {}
 };
 
-inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
-{
-  if ( nkp.availableEmpty() )
-  {
-    ERR << "No Item to select: " << nkp << endl;
-    return false;
-    ZYPP_THROW( Exception("No Item to select") );
-  }
-
-  if ( arch != Arch() )
-  {
-    typeof( nkp.availableBegin() ) it =  nkp.availableBegin();
-    for ( ; it != nkp.availableEnd(); ++it )
-    {
-      if ( (*it)->arch() == arch )
-       return (*it).status().setTransact( true, ResStatus::USER );
-    }
-  }
-
-  return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
-}
-
 ///////////////////////////////////////////////////////////////////
 
 bool solve()
 {
   bool rres = false;
   {
-    zypp::base::LogControl::TmpLineWriter shutUp;
+    //zypp::base::LogControl::TmpLineWriter shutUp;
     rres = getZYpp()->resolver()->resolvePool();
   }
   if ( ! rres )
@@ -226,44 +245,18 @@ bool solve()
 
 bool install()
 {
-  SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
+  ZYppCommitPolicy pol;
+  pol.dryRun(true);
+  pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
+  SEC << getZYpp()->commit( pol ) << endl;
   return true;
 }
 
-///////////////////////////////////////////////////////////////////
-
-struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
+void testcase()
 {
-  virtual void start( const Resolvable::constPtr & script_r,
-                      const Pathname & path_r,
-                      Task task_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << script_r << endl
-    << "  " << path_r   << endl
-    << "  " << task_r   << endl;
-  }
-
-  virtual bool progress( Notify notify_r, const std::string & text_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << notify_r << endl
-    << "  " << text_r   << endl;
-    return true;
-  }
-
-  virtual void problem( const std::string & description_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << description_r << endl;
-  }
-
-  virtual void finish()
-  {
-    SEC << __FUNCTION__ << endl;
-  }
+  getZYpp()->resolver()->createSolverTestcase( "./solverTestcase" );
+}
 
-};
 ///////////////////////////////////////////////////////////////////
 
 struct DigestReceive : public callback::ReceiveReport<DigestReport>
@@ -314,14 +307,20 @@ struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeRep
 {
   virtual Action requestMedia( Url & source
                                , unsigned mediumNr
+                               , const std::string & label
                                , Error error
-                               , const std::string & description )
+                               , const std::string & description
+                               , const std::vector<std::string> & devices
+                               , unsigned int & dev_current )
   {
     SEC << __FUNCTION__ << endl
     << "  " << source << endl
     << "  " << mediumNr << endl
+    << "  " << label << endl
     << "  " << error << endl
-    << "  " << description << endl;
+    << "  " << description << endl
+    << "  " << devices << endl
+    << "  " << dev_current << endl;
     return IGNORE;
   }
 };
@@ -359,6 +358,8 @@ void ttt( const char * lhs, const char * rhs )
   DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
 }
 
+namespace zypp
+{
 namespace filter
 {
   template <class _MemFun, class _Value>
@@ -381,8 +382,6 @@ namespace filter
   { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
 }
 
-namespace zypp
-{
 }
 
 template <class L>
@@ -413,6 +412,66 @@ void testCMP( const L & lhs, const R & rhs )
 #undef OUTS
 }
 
+#include "zypp/Locks.h"
+#include "zypp/target/HardLocksFile.h"
+inline PoolQuery makeTrivialQuery( IdString ident_r )
+{
+  sat::Solvable::SplitIdent ident( ident_r );
+
+  PoolQuery q;
+  q.addAttribute( sat::SolvAttr::name, ident.name().asString() );
+  q.addKind( ident.kind() );
+  q.setMatchExact();
+  q.setCaseSensitive(true);
+  return q;
+}
+inline PoolQuery makeTrivialQuery( const char * ch )
+{ return makeTrivialQuery( IdString(ch) ); }
+void lktest()
+{
+  static unsigned i = 0;
+  ResPool pool( ResPool::instance() );
+  target::HardLocksFile::Data newdata;
+  pool.getHardLockQueries( newdata );
+  SEC << '[' << i++ << ']' << newdata << endl;
+}
+
+
+Capability guessPackageSpec( const std::string & str_r )
+{
+  return Capability::guessPackageSpec( str_r );
+}
+
+
+
+
+void cut( const Capability & cap )
+{
+  CapDetail detail( cap.detail() );
+  if ( detail.isSimple() )
+  {
+    MIL << detail.kind() << ": " << detail.name();
+    if ( detail.hasArch() )
+      MIL << " (" << detail.arch() << ")";
+    if ( detail.isVersioned() )
+      MIL << " " << detail.op() << " " << detail.ed();
+    MIL << endl;
+  }
+  else
+  {
+    MIL << "---???---" << endl;
+  }
+}
+
+namespace zypp { namespace target {
+  void XRunUpdateMessages( const Pathname & root_r,
+                           const Pathname & messagesPath_r,
+                           const std::vector<sat::Solvable> & checkPackages_r,
+                           ZYppCommitResult & result_r );
+
+}}
+using zypp::target::XRunUpdateMessages;
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -420,86 +479,150 @@ void testCMP( const L & lhs, const R & rhs )
 */
 int main( int argc, char * argv[] )
 try {
-  //zypp::base::LogControl::instance().logfile( "log.restrict" );
+  --argc,++argv;
+  if (0) {
+    // download the repo index file
+    media::MediaManager mediamanager;
+    media::MediaAccessId mid = mediamanager.open( Url("http://download.opensuse.org") );
+    mediamanager.attach( mid );
+  }
+  zypp::base::LogControl::instance().logToStdErr();
   INT << "===[START]==========================================" << endl;
-  setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
+  ZConfig::instance();
 
-  sat::Pool satpool( sat::Pool::instance() );
   ResPool   pool( ResPool::instance() );
-  USR << "pool: " << pool << endl;
-
-  RepoManager repoManager( makeRepoManager( sysRoot ) );
-  RepoInfoList repos = repoManager.knownRepositories();
+  sat::Pool satpool( sat::Pool::instance() );
 
-  // launch repos
-  for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+  if ( 0 )
   {
-    RepoInfo & nrepo( *it );
-    SEC << nrepo << endl;
-
-    if ( ! nrepo.enabled() )
-      continue;
-
-    if ( ! repoManager.isCached( nrepo ) || /*force*/false )
+    Measure x( "INIT TARGET" );
     {
-      if ( repoManager.isCached( nrepo ) )
       {
-       SEC << "cleanCache" << endl;
-       repoManager.cleanCache( nrepo );
+        //zypp::base::LogControl::TmpLineWriter shutUp;
+        getZYpp()->initializeTarget( sysRoot );
       }
-      SEC << "refreshMetadata" << endl;
-      repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
-      SEC << "buildCache" << endl;
-      repoManager.buildCache( nrepo );
+      getZYpp()->target()->load();
+      USR << "baseproduct:               " << getZYpp()->target()->baseProduct() << endl;
+      USR << "targetDistribution:        " << getZYpp()->target()->targetDistribution() << endl;
+      USR << "targetDistributionRelease: " << getZYpp()->target()->targetDistributionRelease() << endl;
+      dumpRange( USR << "Product ", pool.byKindBegin<Product>(), pool.byKindEnd<Product>() ) << endl;
     }
   }
 
-  // create from cache:
+  if ( 0 )
   {
-    Measure x( "CREATE FROM CACHE" );
-    for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+    RepoManager repoManager( makeRepoManager( sysRoot ) );
+    ServiceInfoList services = repoManager.knownServices();
+
+    for ( ServiceInfoList::iterator it = services.begin(); it != services.end(); ++it )
     {
-      RepoInfo & nrepo( *it );
-      if ( ! nrepo.enabled() )
+      ServiceInfo & nservice( *it );
+      SEC << nservice << endl;
+
+      if ( ! nservice.enabled() )
         continue;
 
-      Measure x( "CREATE FROM CACHE "+nrepo.alias() );
-      repoManager.loadFromCache( nrepo );
-      USR << "pool: " << pool << endl;
+      repoManager.refreshService( nservice );
     }
   }
 
   if ( 1 )
   {
-    Measure x( "INIT TARGET" );
+    RepoManager repoManager( makeRepoManager( sysRoot ) );
+    RepoInfoList repos = repoManager.knownRepositories();
+
+    // launch repos
+    for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
     {
-//       zypp::base::LogControl::TmpLineWriter shutUp;
-      getZYpp()->initializeTarget( sysRoot );
-      getZYpp()->target()->load();
+      RepoInfo & nrepo( *it );
+      SEC << nrepo << endl;
+
+      if ( ! nrepo.enabled() )
+        continue;
+
+      if ( ! repoManager.isCached( nrepo ) || nrepo.type() == repo::RepoType::RPMPLAINDIR )
+      {
+        if ( repoManager.isCached( nrepo ) )
+        {
+          SEC << "cleanCache" << endl;
+          repoManager.cleanCache( nrepo );
+        }
+        SEC << "refreshMetadata" << endl;
+        //repoManager.refreshMetadata( nrepo );
+        SEC << "buildCache" << endl;
+        repoManager.buildCache( nrepo );
+      }
+    }
+
+    // create from cache:
+    {
+      Measure x( "CREATE FROM CACHE" );
+      for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+      {
+        RepoInfo & nrepo( *it );
+        if ( ! nrepo.enabled() )
+          continue;
+
+        Measure x( "CREATE FROM CACHE "+nrepo.alias() );
+        try
+        {
+          repoManager.loadFromCache( nrepo );
+        }
+        catch ( const Exception & exp )
+        {
+          MIL << "Try to rebuild cache..." << endl;
+          SEC << "cleanCache" << endl;
+          repoManager.cleanCache( nrepo );
+          SEC << "buildCache" << endl;
+          repoManager.buildCache( nrepo );
+          SEC << "Create from cache" << endl;
+          repoManager.loadFromCache( nrepo );
+        }
+
+        //USR << "pool: " << pool << endl;
+      }
     }
   }
 
-  MIL << satpool << endl;
+  dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
   USR << "pool: " << pool << endl;
 
-  vdumpPoolStats( USR << "Pool:"<< endl,
-                  pool.begin(), pool.end() ) << endl;
+  ///////////////////////////////////////////////////////////////////
 
+  if ( 0 )
+  {
+    Measure x( "Upgrade" );
+    getZYpp()->resolver()->doUpgrade();
+  }
 
-  //waitForInput();
-  //std::for_each( pool.begin(), pool.end(), Xprint() );
+  ///////////////////////////////////////////////////////////////////
 
-//   for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
-//   {
-//     MIL << *it << endl;
-//     //MIL << dump(*it) << endl;
-//   }
 
-  ///////////////////////////////////////////////////////////////////
+
+
+
+#if 1
+  getZYpp()->resolver()->addRequire( Capability("amarok") );
+  pool.byKindBegin<Package>()->status().setTransact( true, ResStatus::USER );
+  solve();
+  vdumpPoolStats( USR << "Transacting:"<< endl,
+                  make_filter_begin<resfilter::ByTransact>(pool),
+                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+#endif
+
+  //////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;
 }
+catch ( const Exception & exp )
+{
+  INT << exp << endl << exp.historyAsString();
+  throw;
+}
 catch (...)
-{}
+{
+  throw;
+}
+