backup
authorMichael Andres <ma@suse.de>
Tue, 29 Apr 2008 16:19:41 +0000 (16:19 +0000)
committerMichael Andres <ma@suse.de>
Tue, 29 Apr 2008 16:19:41 +0000 (16:19 +0000)
devel/devel.ma/NewPool.cc
zypp/ResPool.cc
zypp/ResPool.h
zypp/ResStatus.cc
zypp/ResStatus.h
zypp/pool/PoolImpl.h
zypp/pool/PoolTraits.h
zypp/target/TargetImpl.cc

index 3f85707..fb28bfe 100644 (file)
@@ -454,33 +454,112 @@ void testCMP( const L & lhs, const R & rhs )
 
 namespace zypp
 {
-//   poolItemIterator
-  template <class _Filter>
-  class PoolFilter
+  /** Helper class to collect (not only) \ref PoolQuery results.
+   *
+   * \note Unfortunately \ref PoolQuery::begin might throw. Exceptions
+   * are caught and the query is treated as empty.
+   *
+   * \ref PoolQueryResult maintains a set of \ref sat::Solvable. You can
+   * add/remove solvables to/from the set defined by:
+   *
+   * \li a single \ref sat::Solvable
+   * \li a \ref PoolQuery
+   * \li an other \ref PoolQueryResult
+   * \li any iterator pair with \c value_type \ref sat::Solvable or \ref PoolQuery
+   *     or \ref PoolQueryResult (any type that fits \c operator+=)
+  */
+  class PoolQueryResult : public sat::SolvIterMixin<PoolQueryResult,std::tr1::unordered_set<sat::Solvable>::const_iterator>
   {
-    typedef filter_iterator<_Filter,ResPool::const_iterator> iterator;
+    public:
+      typedef std::tr1::unordered_set<sat::Solvable>   ResultSet;
+      typedef ResultSet::size_type                      size_type;
+      typedef ResultSet::const_iterator                 const_iterator;
 
     public:
-      PoolFilter()
+      PoolQueryResult()
       {}
 
-      PoolFilter( const _Filter & filter_r )
-      : _filter( filter_r )
-      {}
+      explicit PoolQueryResult( sat::Solvable result_r )
+      { _result.insert( result_r ); }
+
+      explicit PoolQueryResult( const PoolQuery & query_r )
+      { operator+=( query_r ); }
+
+      template<class _QueryResultIter>
+      PoolQueryResult( _QueryResultIter begin_r, _QueryResultIter end_r )
+      {
+        for_( it, begin_r, end_r )
+        {
+          operator+=( *it );
+        }
+      }
+
+    public:
+      /***/
+      bool empty() const
+      { return _result.empty(); }
+      /***/
+      size_type size() const
+      { return _result.size(); }
+      /***/
+      const_iterator begin() const
+      { return _result.begin(); }
+      /***/
+      const_iterator end() const
+      { return _result.end(); }
 
-      iterator begin() const
-      { return ResPool::instance().filterBegin(_filter); }
+    public:
+      /**
+      */
+      PoolQueryResult & operator+=( const PoolQueryResult & query_r )
+      {
+        if ( ! query_r.empty() )
+          _result.insert( query_r.begin(), query_r.end() );
+        return *this;
+      }
+      /** \overload */
+      PoolQueryResult & operator+=( const PoolQuery & query_r )
+      { return operator+=( PoolQueryResult( query_r ) ); }
+      /** \overload */
+      PoolQueryResult & operator+=( sat::Solvable result_r )
+      { _result.insert( result_r ); return *this; }
+
+      /**
+      */
+      PoolQueryResult & operator-=( const PoolQueryResult & query_r );
+      /** \overload */
+      PoolQueryResult & operator-=( const PoolQuery & query_r )
+      { return operator-=( PoolQueryResult( query_r ) ); }
+      /** \overload */
+      PoolQueryResult & operator-=( sat::Solvable result_r )
+      { return operator+=( PoolQueryResult( result_r ) ); }
 
-      iterator end() const
-      { return ResPool::instance().filterEnd(_filter); }
+    public:
+      /**
+      */
+      PoolQueryResult operator+( const PoolQueryResult & query_r ) const
+      { return PoolQueryResult(*this) += query_r; }
+      /** \overload */
+      PoolQueryResult operator+( const PoolQuery & query_r ) const
+      { return PoolQueryResult(*this) += query_r; }
+      /** \overload */
+      PoolQueryResult operator+( sat::Solvable result_r ) const
+      { return PoolQueryResult(*this) += result_r; }
+
+      /**
+      */
+      PoolQueryResult operator-( const PoolQueryResult & query_r ) const
+      { return PoolQueryResult(*this) -= query_r; }
+      /** \overload */
+      PoolQueryResult operator-( const PoolQuery & query_r ) const
+      { return PoolQueryResult(*this) -= query_r; }
+      /** \overload */
+      PoolQueryResult operator-( sat::Solvable result_r ) const
+      { return PoolQueryResult(*this) -= result_r; }
 
     private:
-      _Filter _filter;
+      ResultSet _result;
   };
-
-  template <class _Filter>
-  PoolFilter<_Filter> makePoolFilter( const _Filter & filter_r )
-  { return PoolFilter<_Filter>( filter_r ); }
 }
 
 void tt( const std::string & name_r, ResKind kind_r = ResKind::package )
@@ -502,12 +581,36 @@ void sslk( const std::string & t = std::string() )
   outs << t << ": {" << endl;
   for_( it, pool.begin(), pool.end() )
   {
-    if ( it->status().isSoftLocked() )
+    if ( it->status().isLocked() )
       outs << "    " << *it << endl;
   }
   outs << '}' << endl;
 }
 
+void ssup()
+{
+  ResPool pool( ResPool::instance() );
+
+  ResPool::HardLockQueries newLocks;
+
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "kde3*" );
+    q.setMatchGlob();
+    dumpRange( DBG, q.begin(), q.end() ) << endl;
+    newLocks.push_back( q );
+  }
+  {
+    PoolQuery q;
+    q.addAttribute( sat::SolvAttr::name, "kde4*" );
+    q.setMatchGlob();
+    dumpRange( DBG, q.begin(), q.end() ) << endl;
+    newLocks.push_back( q );
+  }
+
+  pool.setHardLockQueries( newLocks );
+
+}
 
 
 /******************************************************************
@@ -521,10 +624,14 @@ try {
   ++argv;
   zypp::base::LogControl::instance().logToStdErr();
   INT << "===[START]==========================================" << endl;
+  ZConfig::instance();
 
   ResPool   pool( ResPool::instance() );
   sat::Pool satpool( sat::Pool::instance() );
 
+  ssup();
+  //sslk( "START" );
+
   if ( 1 )
   {
     RepoManager repoManager( makeRepoManager( sysRoot ) );
@@ -579,6 +686,8 @@ try {
         }
 
         USR << "pool: " << pool << endl;
+
+        sslk( nrepo.alias() );
       }
     }
   }
@@ -592,6 +701,7 @@ try {
         getZYpp()->initializeTarget( sysRoot );
       }
       getZYpp()->target()->load();
+      sslk( "TARGET" );
     }
   }
 
@@ -609,6 +719,13 @@ try {
   ///////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
 
+
+
+  ///////////////////////////////////////////////////////////////////
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+  return 0;
+
   SEC << zypp::getZYpp()->diskUsage() << endl;
 
   if ( 0 )
index 31e32d5..63e9f37 100644 (file)
@@ -95,6 +95,26 @@ namespace zypp
   void ResPool::getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
   { _pimpl->getActiveSoftLocks( activeLocks_r ); }
 
+
+  bool ResPool::hardLockQueriesEmpty() const
+  { return _pimpl->hardLockQueries().empty(); }
+
+  ResPool::size_type ResPool::hardLockQueriesSize() const
+  { return _pimpl->hardLockQueries().size(); }
+
+  ResPool::hardLockQueries_iterator ResPool::hardLockQueriesBegin() const
+  { return _pimpl->hardLockQueries().begin(); }
+
+  ResPool::hardLockQueries_iterator ResPool::hardLockQueriesEnd() const
+  { return _pimpl->hardLockQueries().end(); }
+
+  void ResPool::setHardLockQueries( const HardLockQueries & newLocks_r )
+  { _pimpl->setHardLockQueries( newLocks_r ); }
+
+  void ResPool::getHardLockQueries( HardLockQueries & activeLocks_r )
+  { _pimpl->getHardLockQueries( activeLocks_r ); }
+
+
   const pool::PoolTraits::ItemContainerT & ResPool::store() const
   { return _pimpl->store(); }
 
index 38737be..5e51288 100644 (file)
@@ -333,6 +333,35 @@ namespace zypp
       */
       void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
       //@}
+
+    public:
+      /** \name Handle hard locks (e.g set from /etc/zypp/locks).
+       *
+       * As this kind of lock is query based, it's quite expensive.
+       *
+       * These queries are re-evaluated when adding new repos to the pool.
+       */
+      //@{
+      typedef pool::PoolTraits::HardLockQueries           HardLockQueries;
+      typedef pool::PoolTraits::hardLockQueries_iterator  hardLockQueries_iterator;
+
+      bool hardLockQueriesEmpty() const;
+      size_type hardLockQueriesSize() const;
+      hardLockQueries_iterator hardLockQueriesBegin() const;
+      hardLockQueries_iterator hardLockQueriesEnd() const;
+
+      /** Set a new set of queries.
+       * The hard-locks of existing PoolItems are adjusted according
+       * to the queries. (usually called on target load)
+       */
+      void setHardLockQueries( const HardLockQueries & newLocks_r );
+
+      /** Suggest a new set of queries based on the current selection.
+       * (usually remembered on commit).
+       */
+      void getHardLockQueries( HardLockQueries & activeLocks_r );
+      //@}
+
     private:
       const pool::PoolTraits::ItemContainerT & store() const;
       const pool::PoolTraits::Id2ItemT & id2item() const;
index 7201a04..d21c1e3 100644 (file)
@@ -58,7 +58,7 @@ namespace zypp
   ResStatus::ResStatus (enum StateValue s, enum ValidateValue v, enum TransactValue t, enum InstallDetailValue i, enum RemoveDetailValue r, enum SolverStateValue ssv)
     : _bitfield (s)
   {
-    fieldValueAssign<ValidateField>(v);      
+    fieldValueAssign<ValidateField>(v);
     fieldValueAssign<TransactField>(t);
     if (t == TRANSACT) {
        if (s == INSTALLED) fieldValueAssign<TransactDetailField>(r);
@@ -99,8 +99,10 @@ namespace zypp
 
     str << (obj.isRecommended() ? "r" : "" );
 
-    str << (obj.isSuggested() ? "s" : "" );    
-
+    str << (obj.isSuggested() ? "s" : "" );
+#ifdef HARDLOCKTEST
+    str << (obj.isUserLockQueryMatch() ?  "L" : "_" );
+#endif
     return str;
   }
 
index ab47df4..0ae5c72 100644 (file)
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
+  namespace resstatus
+  {
+    class UserLockQueryManip;
+  }
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : ResStatus
@@ -67,6 +72,7 @@ namespace zypp
     typedef bit::Range<FieldType,TransactDetailField::end,   1> SolverStateField;
     typedef bit::Range<FieldType,SolverStateField::end,      1> LicenceConfirmedField;
     typedef bit::Range<FieldType,LicenceConfirmedField::end, 2> WeakField;
+    typedef bit::Range<FieldType,WeakField::end,             1> UserLockQueryField; // internal
     // enlarge FieldType if more bit's needed. It's not yet
     // checked by the compiler.
     //@}
@@ -142,6 +148,12 @@ namespace zypp
        RECOMMENDED             = bit::RangeValue<WeakField,2>::value,
        SUGGESTED_AND_RECOMMENDED = bit::RangeValue<WeakField,3>::value
       };
+
+    enum UserLockQuery // internal
+      {
+        USERLOCK_NOMATCH       = bit::RangeValue<UserLockQueryField,0>::value,
+        USERLOCK_MATCH         = bit::RangeValue<UserLockQueryField,1>::value
+      };
     //@}
 
   public:
@@ -284,6 +296,19 @@ namespace zypp
     bool isToBeUninstalledSoft () const
     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( SOFT_REMOVE ); }
 
+  private:
+
+    /** \name Internal hard lock maintainance */
+    //@{
+    friend class resstatus::UserLockQueryManip;
+
+    bool isUserLockQueryMatch() const
+    { return fieldValueIs<UserLockQueryField>( USERLOCK_MATCH ); }
+
+    void setUserLockQueryMatch( bool match_r )
+    { fieldValueAssign<UserLockQueryField>( match_r ? USERLOCK_MATCH : USERLOCK_NOMATCH ); }
+    //@}
+
   public:
 
     //------------------------------------------------------------------------
index c24c12c..e4396b6 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "zypp/pool/PoolTraits.h"
 #include "zypp/ResPoolProxy.h"
+#include "zypp/PoolQuery.h"
 
 #include "zypp/sat/Pool.h"
 
@@ -138,9 +139,31 @@ namespace zypp
         //
         ///////////////////////////////////////////////////////////////////
       public:
-        bool hardLockAppliesTo( sat::Solvable solv_r ) const
+        typedef PoolTraits::HardLockQueries           HardLockQueries;
+        typedef PoolTraits::hardLockQueries_iterator  hardLockQueries_iterator;
+
+        const HardLockQueries & hardLockQueries() const
+        { return _hardLockQueries; }
+
+        void reapplyHardLocks() const
+        {
+#ifdef HARDLOCKTEST
+          SEC << "reapplyHardLocks " << endl;
+#endif
+        }
+
+        void setHardLockQueries( const HardLockQueries & newLocks_r )
         {
-          return false;
+          MIL << "Apply " << newLocks_r.size() << " HardLockQueries" << endl;
+          _hardLockQueries = newLocks_r;
+          // now adjust the pool status
+          // TBD
+        }
+
+        void getHardLockQueries( HardLockQueries & activeLocks_r )
+        {
+          activeLocks_r = _hardLockQueries; // current queries
+          // TBD
         }
 
       public:
@@ -163,7 +186,7 @@ namespace zypp
             if ( ! it->status().isKept() )
               continue;
 
-            if ( newLocks_r.find( it->satSolvable().ident() ) != newLocks_r.end() )
+            if ( autoSoftLockAppliesTo( it->satSolvable() ) )
               it->status().setSoftLock( ResStatus::USER );
             else
               it->status().resetTransact( ResStatus::USER );
@@ -172,7 +195,7 @@ namespace zypp
 
         void getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
         {
-          activeLocks_r = _autoSoftLocks; // currentsoft-locks
+          activeLocks_r = _autoSoftLocks; // current soft-locks
           AutoSoftLocks todel;            // + names to be deleted
           AutoSoftLocks toins;            // - names to be installed
 
@@ -180,7 +203,7 @@ namespace zypp
           {
             ResStatus & status( it->status() );
             if ( ! status.isByUser() )
-              continue;
+              continue; // ignore non-uer requests
 
             switch ( status.getTransactValue() )
             {
@@ -212,7 +235,12 @@ namespace zypp
           if ( _storeDirty )
           {
             sat::Pool pool( satpool() );
+            bool addedItems = false;
 
+#ifdef HARDLOCKTEST
+#warning REMOVE FAKE REMOVE FAKE REMOVE FAKE REMOVE FAKE
+            addedItems = true;
+#endif
             if ( pool.capacity() != _store.capacity() )
             {
               _store.resize( pool.capacity() );
@@ -233,19 +261,24 @@ namespace zypp
                 {
                   // new PoolItem to add
                   pi = PoolItem::makePoolItem( s ); // the only way to create a new one!
-                  // and a few checks...
-                  if ( hardLockAppliesTo( s ) )
-                  {
-                    pi.status().setLock( true, ResStatus::USER );
-                  }
-                  else if ( autoSoftLockAppliesTo( s ) )
+                  // and on the fly check for wek locks...
+                  if ( autoSoftLockAppliesTo( s ) )
                   {
                     pi.status().setSoftLock( ResStatus::USER );
                   }
+                  if ( !addedItems )
+                    addedItems = true;
                 }
               }
             }
             _storeDirty = false;
+
+            // Now, as the pool is adjusted, we must reapply those query
+            // based hard locks...
+            if ( addedItems )
+            {
+              reapplyHardLocks();
+            }
           }
           return _store;
         }
@@ -304,6 +337,8 @@ namespace zypp
       private:
         /** Set of solvable idents that should be soft locked per default. */
         AutoSoftLocks                         _autoSoftLocks;
+        /** Set of queries that define hardlocks. */
+        HardLockQueries                       _hardLockQueries;
     };
     ///////////////////////////////////////////////////////////////////
 
index cc78135..0310bab 100644 (file)
@@ -27,6 +27,8 @@
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
+  class PoolQuery;
+
   ///////////////////////////////////////////////////////////////////
   namespace pool
   { /////////////////////////////////////////////////////////////////
@@ -138,13 +140,17 @@ namespace zypp
       typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
                                                         byIdent_iterator;
 
-      /* list of known Repositories */
+      /** list of known Repositories */
       typedef sat::Pool::RepositoryIterator            repository_iterator;
 
-      /* soft locks */
+      /** soft locks */
       typedef std::tr1::unordered_set<IdString>                AutoSoftLocks;
       typedef AutoSoftLocks::const_iterator             autoSoftLocks_iterator;
 
+      /** hard locks from etc/zypp/locks */
+      typedef std::list<PoolQuery>                     HardLockQueries;
+      typedef HardLockQueries::const_iterator          hardLockQueries_iterator;
+
       typedef PoolImpl                   Impl;
       typedef shared_ptr<PoolImpl>       Impl_Ptr;
       typedef shared_ptr<const PoolImpl> Impl_constPtr;
index 255ff06..8579b6d 100644 (file)
@@ -117,7 +117,7 @@ namespace zypp
       // path: directory where to look
       // name,version,release: Script name must match 'name-version.release-' prefix
       //
-#warning nedds to be reimplemented excetion safe
+#warning needs to be reimplemented exception safe
       void RunUpdateScript(Pathname path, std::string name, std::string version, std::string release)
       {
        // open the scripts directory