Cleanup unused /var/lib/zypp/cache in migrate_sources
[platform/upstream/libzypp.git] / devel / devel.ma / NewPool.cc
index 6cbe662..959959c 100644 (file)
@@ -2,36 +2,27 @@
 
 #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/ProvideNumericId.h>
 #include <zypp/AutoDispose.h>
 
-#include "zypp/ZYppFactory.h"
 #include "zypp/ResPoolProxy.h"
-#include <zypp/CapMatchHelper.h>
 
 #include "zypp/ZYppCallbacks.h"
 #include "zypp/NVRAD.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResFilters.h"
 #include "zypp/CapFilters.h"
-#include "zypp/Package.h"
-#include "zypp/Pattern.h"
-#include "zypp/Language.h"
+#include "zypp/ResObjects.h"
 #include "zypp/Digest.h"
 #include "zypp/PackageKeyword.h"
 #include "zypp/ManagedFile.h"
 #include "zypp/NameKindProxy.h"
 #include "zypp/pool/GetResolvablesToInsDel.h"
 
-#include "zypp/parser/TagParser.h"
-#include "zypp/parser/susetags/PackagesFileReader.h"
-#include "zypp/parser/susetags/PackagesLangFileReader.h"
-#include "zypp/parser/susetags/PatternFileReader.h"
-#include "zypp/parser/susetags/ContentFileReader.h"
-#include "zypp/parser/susetags/RepoIndex.h"
-#include "zypp/parser/susetags/RepoParser.h"
-#include "zypp/cache/CacheStore.h"
 #include "zypp/RepoManager.h"
 #include "zypp/RepoInfo.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/detail/PoolMember.h"
+#include "zypp/sat/detail/PoolImpl.h"
+
+#include <zypp/base/GzStream.h>
+
+#include <boost/mpl/int.hpp>
+
 using namespace std;
 using namespace zypp;
 using namespace zypp::functor;
 using namespace zypp::ui;
-using zypp::parser::TagParser;
 
 ///////////////////////////////////////////////////////////////////
 
-static const Pathname sysRoot( "/Local/ROOT" );
+static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
@@ -116,54 +116,6 @@ namespace zypp
       }
 }
 
-template<class _Res>
-Selectable::Ptr getSel( const std::string & name_r )
-{
-  ResPoolProxy uipool( getZYpp()->poolProxy() );
-  for_(it, uipool.byKindBegin<_Res>(), uipool.byKindEnd<_Res>() )
-  {
-    if ( (*it)->name() == name_r )
-      return (*it);
-  }
-  return 0;
-}
-
-template<class _Res>
-PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
-{
-  PoolItem ret;
-  ResPool pool( getZYpp()->pool() );
-  for_(it, pool.byNameBegin(name_r), pool.byNameEnd(name_r) )
-  {
-    if ( !ret && isKind<_Res>( (*it).resolvable() )
-         && ( ed_r == Edition() || ed_r == (*it)->edition() )
-         && ( arch_r == Arch()  || arch_r == (*it)->arch()  ) )
-    {
-      ret = (*it);
-      MIL << "    ->" << *it << endl;
-    }
-    else
-    {
-      DBG << "     ?" << *it << endl;
-    }
-  }
-  return ret;
-}
-template<class _Res>
-PoolItem getPi( const std::string & name_r )
-{
-  return getPi<_Res>( name_r, Edition(), Arch() );
-}
-template<class _Res>
-PoolItem getPi( const std::string & name_r, const Edition & ed_r )
-{
-  return getPi<_Res>( name_r, ed_r, Arch() );
-}
-template<class _Res>
-PoolItem getPi( const std::string & name_r, const Arch & arch_r )
-{
-  return getPi<_Res>( name_r, Edition(), arch_r );
-}
 
 void dbgDu( Selectable::Ptr sel )
 {
@@ -187,55 +139,15 @@ struct Xprint
 {
   bool operator()( const PoolItem & obj_r )
   {
-    if ( obj_r.status().isLocked() )
-      SEC << obj_r << endl;
+    //MIL << obj_r << endl;
+    //DBG << " -> " << obj_r->satSolvable() << endl;
 
-//     handle( asKind<Package>( obj_r ) );
-//     handle( asKind<Patch>( obj_r ) );
-//     handle( asKind<Pattern>( obj_r ) );
-//     handle( asKind<Product>( obj_r ) );
     return true;
   }
 
-  void handle( const Package_constPtr & p )
-  {
-    if ( !p )
-      return;
-
-    WAR << p->size() << endl;
-    MIL << p->diskusage() << endl;
-  }
-
-  void handle( const Patch_constPtr & p )
-  {
-    if ( !p )
-      return;
-  }
-
-  void handle( const Pattern_constPtr & p )
-  {
-    if ( !p )
-      return;
-
-    if ( p->vendor().empty() )
-      ERR << p << endl;
-    else if ( p->vendor() == "SUSE (assumed)" )
-      SEC << p << endl;
-  }
-
-  void handle( const Product_constPtr & p )
-  {
-    if ( !p )
-      return;
-
-    USR << p << endl;
-    USR << p->vendor() << endl;
-    USR << p->type() << endl;
-  }
-
-  template<class _C>
-  bool operator()( const _C & obj_r )
+  bool operator()( const sat::Solvable & obj_r )
   {
+    //dumpOn( MIL, obj_r ) << endl;
     return true;
   }
 };
@@ -298,26 +210,11 @@ inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
 
 ///////////////////////////////////////////////////////////////////
 
-bool solve( bool establish = false )
+bool solve()
 {
-  if ( establish )
-  {
-    bool eres = false;
-    {
-      zypp::base::LogControl::TmpLineWriter shutUp;
-      eres = getZYpp()->resolver()->establishPool();
-    }
-    if ( ! eres )
-    {
-      ERR << "establish " << eres << endl;
-      return false;
-    }
-    MIL << "establish " << eres << endl;
-  }
-
   bool rres = false;
   {
-    zypp::base::LogControl::TmpLineWriter shutUp;
+    //zypp::base::LogControl::TmpLineWriter shutUp;
     rres = getZYpp()->resolver()->resolvePool();
   }
   if ( ! rres )
@@ -439,25 +336,136 @@ namespace container
     bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
     { return cont.find( val ) != cont.end(); }
 }
+///////////////////////////////////////////////////////////////////
 
-struct Xverscmp
+void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
 {
-  Xverscmp( ostream * outs_r = 0 )
-  : _outs( outs_r )
-  {}
+  SEC << *l << " - " << *r << endl;
+  INT << "== " << (l==r) << endl;
+  INT << "!= " << (l!=r) << endl;
+}
 
-  bool operator()( const Edition & lhs, const Edition & rhs )
+bool isTrue()  { return true; }
+bool isFalse() { return false; }
+
+void dumpIdStr()
+{
+  for ( int i = -3; i < 30; ++i )
   {
-    if ( _outs )
-    {
-      int res = lhs.compare( rhs );
-      (*_outs) << lhs << " <> " << rhs << " = " << res << endl;
-    }
-    return true;
+    DBG << i << '\t' << IdString( i ) << endl;
   }
+}
+
+void ttt( const char * lhs, const char * rhs )
+{
+  DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
+}
+
+namespace filter
+{
+  template <class _MemFun, class _Value>
+  class HasValue
+  {
+    public:
+      HasValue( _MemFun fun_r, _Value val_r )
+      : _fun( fun_r ), _val( val_r )
+      {}
+      template <class _Tp>
+      bool operator()( const _Tp & obj_r ) const
+      { return( _fun && (obj_r.*_fun)() == _val ); }
+    private:
+      _MemFun _fun;
+      _Value  _val;
+  };
+
+  template <class _MemFun, class _Value>
+  HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
+  { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
+}
+
+namespace zypp
+{
+}
+
+template <class L>
+struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
+
+template <class L>
+std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
+{ const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
+
+template <class L>
+_TestO<L> testO( const L & lhs )
+{ return _TestO<L>( lhs ); }
+
+template <class L, class R>
+void testCMP( const L & lhs, const R & rhs )
+{
+  MIL << "LHS " << testO(lhs) << endl;
+  MIL << "RHS " << rhs << endl;
+
+#define OUTS(S) DBG << #S << ": " << (S) << endl
+  OUTS( lhs.compare(rhs) );
+  OUTS( lhs != rhs );
+  OUTS( lhs <  rhs );
+  OUTS( lhs <= rhs );
+  OUTS( lhs == rhs );
+  OUTS( lhs >= rhs );
+  OUTS( lhs >  rhs );
+#undef OUTS
+}
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace sat
+{ /////////////////////////////////////////////////////////////////
+
+  class ByLocaleSupport
+  {
+    private:
+      typedef bool (sat::Solvable::*LS1) (const Locale &) const;
+      typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
+
+    public:
+      /** Solvables with locale support. */
+      ByLocaleSupport()
+      : _sel( mem_fun_ref( &sat::Solvable::supportsLocales ) )
+      {}
+
+      /** Solvables supporting \c locale_r. */
+      ByLocaleSupport( const Locale & locale_r )
+      : _sel( bind( mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
+      {}
+
+      /** Solvables supporting at least one locale in \c locales_r. */
+      ByLocaleSupport( const LocaleSet & locales_r )
+      : _sel( bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
+      {}
+
+    public:
+      bool operator()( const sat::Solvable & solv_r ) const
+      { return _sel && _sel( solv_r ); }
+
+
+      template<class _Solv>
+      bool operator()( const _Solv & solv_r ) const
+      { return operator()( solv_r.satSolvable() ); }
+
+    private:
+      function<bool(const sat::Solvable &)> _sel;
+  };
+
+
+  /////////////////////////////////////////////////////////////////
+} // namespace sat
+///////////////////////////////////////////////////////////////////
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-  ostream * _outs;
-};
 
 /******************************************************************
 **
@@ -465,16 +473,18 @@ struct Xverscmp
 **      FUNCTION TYPE : int
 */
 int main( int argc, char * argv[] )
-{
+try {
   //zypp::base::LogControl::instance().logfile( "log.restrict" );
   INT << "===[START]==========================================" << endl;
 
-  setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
+  sat::Pool satpool( sat::Pool::instance() );
+  ResPool   pool( ResPool::instance() );
+  USR << "pool: " << pool << endl;
 
   RepoManager repoManager( makeRepoManager( sysRoot ) );
   RepoInfoList repos = repoManager.knownRepositories();
-  // SEC << "/Local/ROOT " << repos << endl;
 
+  // launch repos
   for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
   {
     RepoInfo & nrepo( *it );
@@ -483,7 +493,7 @@ int main( int argc, char * argv[] )
     if ( ! nrepo.enabled() )
       continue;
 
-    if ( ! repoManager.isCached( nrepo ) || 0 )
+    if ( ! repoManager.isCached( nrepo ) || /*force*/false )
     {
       if ( repoManager.isCached( nrepo ) )
       {
@@ -495,54 +505,90 @@ int main( int argc, char * argv[] )
       SEC << "buildCache" << endl;
       repoManager.buildCache( nrepo );
     }
+  }
 
-    SEC << "createFromCache" << endl;
-    Repository nrep( repoManager.createFromCache( nrepo ) );
-    const zypp::ResStore & store( nrep.resolvables() );
-    dumpPoolStats( SEC << "Store: " << endl, store.begin(), store.end() ) << endl;
-    getZYpp()->addResolvables( store );
+  // 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() );
+      repoManager.loadFromCache( nrepo );
+      USR << "pool: " << pool << endl;
+    }
   }
 
-  if ( 1 )
+  if ( 0 )
   {
+    Measure x( "INIT TARGET" );
     {
-      zypp::base::LogControl::TmpLineWriter shutUp;
-      getZYpp()->initTarget( sysRoot );
-      //getZYpp()->initTarget( "/" );
+      getZYpp()->initializeTarget( sysRoot );
+      getZYpp()->target()->load();
     }
-    SEC << "Added target " << endl;
-    dumpPoolStats( SEC << "Store: " << endl,
-                   getZYpp()->target()->resolvables().begin(),
-                   getZYpp()->target()->resolvables().end() ) << endl;
   }
 
-  ResPool pool( getZYpp()->pool() );
   USR << "pool: " << pool << endl;
+  ///////////////////////////////////////////////////////////////////
 
-  {
-    Measure x( "Cross pool edition compare" );
-    //ofstream out( "verscmp.new" );
+  satpool.addRequestedLocale( Locale("de") );
+  satpool.addRequestedLocale( Locale("cs") );
 
-    std::set<Edition> editions;
-    for_( it, pool.begin(), pool.end() )
-    {
-      editions.insert( (*it)->edition() );
-    }
-    SEC << "Num Editions " << editions.size() << endl;
-    for ( unsigned i = 5; i; --i )
+  LocaleSet s;
+  s.insert( Locale("de") );
+
+//   MIL << satpool.getAvailableLocales() << endl;
+
+  {
+    Measure x( "de" );
+    sat::ByLocaleSupport f( Locale("de") );
+    for_( it, satpool.filterBegin(f), satpool.filterEnd(f) )
     {
-      Measure x( "pass " );
-      invokeOnEach( editions.begin(), editions.end(),
-                    editions.begin(), editions.end(),
-                    Xverscmp() );
+      MIL << *it << endl;
     }
   }
 
+
+
+
+
+  //MIL << sat::WhatProvides( Capability("amarok") ) << endl;
+  //MIL << sat::WhatProvides( Capability("amarok == 1.4.7-37.4") ) << endl;
+
+  if ( 0 )
+  {
+    Measure x( "Upgrade" );
+    UpgradeStatistics u;
+    getZYpp()->resolver()->doUpgrade( u );
+  }
+
+
+  if ( 0 ) {
+  PoolItem pi ( getPi<Package>("amarok") );
+  MIL << pi << endl;
+  if ( pi )
+  {
+    pi.status().setTransact( true, ResStatus::USER );
+    solve();
+    vdumpPoolStats( USR << "Transacting:"<< endl,
+                    make_filter_begin<resfilter::ByTransact>(pool),
+                    make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+
+  }
+  }
+  //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
+  //waitForInput();
+
   //std::for_each( pool.begin(), pool.end(), Xprint() );
 
- ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;
 }
+catch (...)
+{}