Enabled Pool to handle automatic soft-locks,
authorMichael Andres <ma@suse.de>
Thu, 24 Apr 2008 16:58:20 +0000 (16:58 +0000)
committerMichael Andres <ma@suse.de>
Thu, 24 Apr 2008 16:58:20 +0000 (16:58 +0000)
except save/restore which is Targets job.

devel/devel.ma/NewPool.cc
devel/devel.ma/Tools.h
zypp/PoolQuery.cc
zypp/ResPool.cc
zypp/ResPool.h
zypp/ResStatus.h
zypp/pool/PoolImpl.h
zypp/pool/PoolTraits.h

index 616f7da..f9efbec 100644 (file)
@@ -495,35 +495,20 @@ void tt( const std::string & name_r, ResKind kind_r = ResKind::package )
   }
 }
 
-bool myfilter( const PoolItem & pi )
+void sslk( const std::string & t = std::string() )
 {
-  if ( pi->name() == "ruby" )
-    return true;
-  return false;
-}
-
-struct Foo : private debug::TraceCAD<Foo>
-{};
-
-namespace zypp
-{
-  namespace sat
+  ResPool pool( ResPool::instance() );
+  ostream & outs( SEC );
+  outs << t << ": {" << endl;
+  for_( it, pool.begin(), pool.end() )
   {
+    if ( it->status().isSoftLocked() )
+      outs << "    " << *it << endl;
   }
+  outs << '}' << endl;
 }
 
-void ditest( Capability cap_r )
-{
-  DBG << "    (" << cap_r.id() << ") " << endl;
-  DBG << "    " << cap_r << endl;
-  DBG << "    " << dump(cap_r) << endl;
-}
 
-void ditest( const std::string & str_r )
-{
-  MIL <<  str_r << endl;
-  ditest( Capability(str_r) );
-}
 
 /******************************************************************
 **
@@ -542,6 +527,14 @@ try {
   USR << "pool: " << pool << endl;
   sat::Pool satpool( sat::Pool::instance() );
 
+  typedef ResPool::AutoSoftLocks          AutoSoftLocks;
+  typedef ResPool::autoSoftLocks_iterator autoSoftLocks_iterator;
+
+  AutoSoftLocks s;
+  //s.insert( IdString("xorg-x11") );
+  pool.setAutoSoftLocks( s );
+  sslk( "START" );
+
   if ( 1 )
   {
     RepoManager repoManager( makeRepoManager( sysRoot ) );
@@ -600,11 +593,14 @@ try {
     }
   }
 
-  if ( 0 )
+  if ( 1 )
   {
     Measure x( "INIT TARGET" );
     {
-      getZYpp()->initializeTarget( sysRoot );
+      {
+        zypp::base::LogControl::TmpLineWriter shutUp;
+        getZYpp()->initializeTarget( sysRoot );
+      }
       getZYpp()->target()->load();
     }
   }
@@ -613,6 +609,7 @@ try {
   USR << "pool: " << pool << endl;
 
   ///////////////////////////////////////////////////////////////////
+
   if ( 0 )
   {
     Measure x( "Upgrade" );
@@ -622,43 +619,35 @@ try {
   ///////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
 
-  ditest("foo");
-  ditest("foo.baa");
-  ditest("foo.i386");
-  ditest("foo.baa < 13");
-  ditest("foo.foo.baa < 13");
-  ditest("foo.foo.i386 < 13");
-  ditest("");
+  sslk( "AFTER LOAD" );
 
-  ///////////////////////////////////////////////////////////////////
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
+  //s.clear();
+  s.insert( IdString("pattern:office") );
+  pool.setAutoSoftLocks( s );
+  sslk( "AFTER RESET" );
 
 
-  if ( 0 ) {
-    Measure x( "PROXY" );
-    pool.proxy();
-  }
+  AutoSoftLocks n;
+  pool.getActiveSoftLocks( s );
+  INT << s << endl;
 
-  if ( 0 ) {
-    Measure x( "ALL PATTERNS" );
+  PoolItem( sat::Solvable(10340) ).status().setTransact( true, ResStatus::USER );
+  PoolItem( sat::Solvable(3500) ).status().setTransact( true, ResStatus::USER );
+  vdumpPoolStats( USR << "Transacting:"<< endl,
+                      make_filter_begin<resfilter::ByTransact>(pool),
+                      make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+  pool.getActiveSoftLocks( s );
+  INT << s << endl;
 
-    for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
-    {
-      Measure x( string("  ") + (*it)->name() );
-      Pattern::Contents c( asKind<Pattern>(*it)->contents() );
-      {
-        Measure x( "    poolitem" );
-        dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
-      }
-      {
-        Measure x( "    selectable" );
-        dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
-      }
-      break;
-    }
-  }
+
+  ///////////////////////////////////////////////////////////////////
+
+  //vdumpPoolStats( USR << "Pool:"<< endl, pool.byKindBegin<Package>(), pool.byKindEnd<Package>() ) << endl;
+
+  ///////////////////////////////////////////////////////////////////
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+  return 0;
 
   SEC << zypp::getZYpp()->diskUsage() << endl;
 
index 455ea40..3f958ac 100644 (file)
@@ -32,6 +32,10 @@ using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 
+#define for_providers_(IT,CAP) for ( sat::WhatProvides::const_iterator IT = sat::WhatProvides( Capability CAP ).begin(), _for_end = sat::WhatProvides().end(); IT != _for_end; ++IT )
+
+///////////////////////////////////////////////////////////////////
+
 void waitForInput()
 {
   int i;
index 7ed3b72..09ec8e0 100644 (file)
@@ -570,7 +570,7 @@ attremptycheckend:
     bool got_match = false;
     if (_has_next)
     {
-      DBG << "last: " << _sid << endl;
+      XXX << "last: " << _sid << endl;
       while (_has_next && !(got_match = matchSolvable()));
     }
 
@@ -581,7 +581,7 @@ attremptycheckend:
       _sid = 0;
     }
 
-    DBG << "next: " << _sid << endl;
+    XXX << "next: " << _sid << endl;
   }
 
   bool PoolQueryIterator::matchSolvable()
index 090f6e6..31e32d5 100644 (file)
@@ -31,7 +31,7 @@ namespace zypp
   //
   ResPool ResPool::instance()
   {
-    static ResPool _val( pool::PoolTraits::Impl_constPtr( new pool::PoolImpl ) );
+    static ResPool _val( pool::PoolTraits::Impl_Ptr( new pool::PoolImpl ) );
     return _val;
   }
 
@@ -40,7 +40,7 @@ namespace zypp
   //   METHOD NAME : ResPool::ResPool
   //   METHOD TYPE : Ctor
   //
-  ResPool::ResPool( pool::PoolTraits::Impl_constPtr impl_r )
+  ResPool::ResPool( pool::PoolTraits::Impl_Ptr impl_r )
   : _pimpl( impl_r )
   {}
 
@@ -66,6 +66,7 @@ namespace zypp
   PoolItem ResPool::find( const sat::Solvable & slv_r ) const
   { return _pimpl->find( slv_r ); }
 
+
   ResPool::size_type ResPool::knownRepositoriesSize() const
   { return _pimpl->knownRepositoriesSize(); }
 
@@ -75,6 +76,25 @@ namespace zypp
   ResPool::repository_iterator ResPool::knownRepositoriesEnd() const
   { return _pimpl->knownRepositoriesEnd(); }
 
+
+  bool ResPool::autoSoftLocksEmpty() const
+  { return _pimpl->autoSoftLocks().empty(); }
+
+  ResPool::size_type ResPool::autoSoftLocksSize() const
+  { return _pimpl->autoSoftLocks().size(); }
+
+  ResPool::autoSoftLocks_iterator ResPool::autoSoftLocksBegin() const
+  { return _pimpl->autoSoftLocks().begin(); }
+
+  ResPool::autoSoftLocks_iterator ResPool::autoSoftLocksEnd() const
+  { return _pimpl->autoSoftLocks().end(); }
+
+  void ResPool::setAutoSoftLocks( const AutoSoftLocks & newLocks_r )
+  { _pimpl->setAutoSoftLocks( newLocks_r ); }
+
+  void ResPool::getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
+  { _pimpl->getActiveSoftLocks( activeLocks_r ); }
+
   const pool::PoolTraits::ItemContainerT & ResPool::store() const
   { return _pimpl->store(); }
 
index ccc4885..38737be 100644 (file)
@@ -299,15 +299,49 @@ namespace zypp
       bool isAvailableLocale( const Locale & locale_r ) const;
       //@}
 
+    public:
+      /** \name Handle automatic soft-locks.
+       *
+       * Solvables with and ident listed here are per default created with
+       * a setSoftLock applied. I.e. the \ref Resolver should not automatically
+       * select them, if they are just recommended.
+       *
+       * This list is considered when adding new repos to the pool. It is
+       * \b not the list of currently softLocked items.
+       *
+       * Mainly used to re-apply soft-locks remembered during the last commit.
+       */
+      //@{
+      typedef pool::PoolTraits::AutoSoftLocks          AutoSoftLocks;
+      typedef pool::PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
+
+      bool autoSoftLocksEmpty() const;
+      size_type autoSoftLocksSize() const;
+      autoSoftLocks_iterator autoSoftLocksBegin() const;
+      autoSoftLocks_iterator autoSoftLocksEnd() const;
+
+      /** Set a new soft-lock list.
+       * The soft-locks of existing PoolItems are adjusted according
+       * to the list. (usually called on target load)
+      */
+      void setAutoSoftLocks( const AutoSoftLocks & newLocks_r );
+
+      /** Suggest a new soft-lock list based on the current selection.
+       * Based on the the current soft-lock list. Items tagged to be
+       * installed are removed, and those tagged to be deleted are added.
+       * (usually remembered on commit).
+      */
+      void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
+      //@}
     private:
       const pool::PoolTraits::ItemContainerT & store() const;
       const pool::PoolTraits::Id2ItemT & id2item() const;
 
     private:
       /** Ctor */
-      ResPool( pool::PoolTraits::Impl_constPtr impl_r );
-      /** Const access to implementation. */
-      pool::PoolTraits::Impl_constPtr _pimpl;
+      ResPool( pool::PoolTraits::Impl_Ptr impl_r );
+      /** Access to implementation. */
+      RW_pointer<pool::PoolTraits::Impl> _pimpl;
   };
   ///////////////////////////////////////////////////////////////////
 
index faeb2e6..ab47df4 100644 (file)
@@ -241,6 +241,9 @@ namespace zypp
     bool isLocked() const
     { return fieldValueIs<TransactField>( LOCKED ); }
 
+    bool isSoftLocked( TransactByValue causer_r = USER ) const
+    { return isKept() && fieldValueIs<TransactByField>( causer_r ); }
+
     bool isKept() const
     { return fieldValueIs<TransactField>( KEEP_STATE ); }
 
index 87e6953..c24c12c 100644 (file)
@@ -143,11 +143,69 @@ namespace zypp
           return false;
         }
 
-        bool softLockAppliesTo( sat::Solvable solv_r ) const
+      public:
+        typedef PoolTraits::AutoSoftLocks          AutoSoftLocks;
+        typedef PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
+
+        const AutoSoftLocks & autoSoftLocks() const
+        { return _autoSoftLocks; }
+
+        bool autoSoftLockAppliesTo( sat::Solvable solv_r ) const
+        { return( _autoSoftLocks.find( solv_r.ident() ) != _autoSoftLocks.end() ); }
+
+        void setAutoSoftLocks( const AutoSoftLocks & newLocks_r )
         {
-          return false;
+          MIL << "Apply " << newLocks_r.size() << " AutoSoftLocks: " << newLocks_r << endl;
+          _autoSoftLocks = newLocks_r;
+          // now adjust the pool status
+          for_( it, begin(), end() )
+          {
+            if ( ! it->status().isKept() )
+              continue;
+
+            if ( newLocks_r.find( it->satSolvable().ident() ) != newLocks_r.end() )
+              it->status().setSoftLock( ResStatus::USER );
+            else
+              it->status().resetTransact( ResStatus::USER );
+          }
         }
 
+        void getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
+        {
+          activeLocks_r = _autoSoftLocks; // currentsoft-locks
+          AutoSoftLocks todel;            // + names to be deleted
+          AutoSoftLocks toins;            // - names to be installed
+
+          for_( it, begin(), end() )
+          {
+            ResStatus & status( it->status() );
+            if ( ! status.isByUser() )
+              continue;
+
+            switch ( status.getTransactValue() )
+            {
+              case ResStatus::KEEP_STATE:
+                activeLocks_r.insert( it->satSolvable().ident() );
+                break;
+              case ResStatus::LOCKED:
+                //  NOOP
+                break;
+              case ResStatus::TRANSACT:
+                (status.isInstalled() ? todel : toins).insert( it->satSolvable().ident() );
+                break;
+            }
+          }
+          for_( it, todel.begin(), todel.end() )
+          {
+            activeLocks_r.insert( *it );
+          }
+          for_( it, toins.begin(), toins.end() )
+          {
+            activeLocks_r.erase( *it );
+          }
+        }
+
+      public:
         const ContainerT & store() const
         {
           checkSerial();
@@ -180,7 +238,7 @@ namespace zypp
                   {
                     pi.status().setLock( true, ResStatus::USER );
                   }
-                  else if ( softLockAppliesTo( s ) )
+                  else if ( autoSoftLockAppliesTo( s ) )
                   {
                     pi.status().setSoftLock( ResStatus::USER );
                   }
@@ -213,7 +271,6 @@ namespace zypp
          return _id2item;
        }
 
-
         ///////////////////////////////////////////////////////////////////
         //
         ///////////////////////////////////////////////////////////////////
@@ -243,6 +300,10 @@ namespace zypp
 
       private:
         mutable shared_ptr<ResPoolProxy>      _poolProxy;
+
+      private:
+        /** Set of solvable idents that should be soft locked per default. */
+        AutoSoftLocks                         _autoSoftLocks;
     };
     ///////////////////////////////////////////////////////////////////
 
index 0858b47..cc78135 100644 (file)
@@ -141,6 +141,10 @@ namespace zypp
       /* list of known Repositories */
       typedef sat::Pool::RepositoryIterator            repository_iterator;
 
+      /* soft locks */
+      typedef std::tr1::unordered_set<IdString>                AutoSoftLocks;
+      typedef AutoSoftLocks::const_iterator             autoSoftLocks_iterator;
+
       typedef PoolImpl                   Impl;
       typedef shared_ptr<PoolImpl>       Impl_Ptr;
       typedef shared_ptr<const PoolImpl> Impl_constPtr;