switch to new locks api
authorJosef Reidinger <jreidinger@suse.cz>
Fri, 11 Apr 2008 10:04:23 +0000 (10:04 +0000)
committerJosef Reidinger <jreidinger@suse.cz>
Fri, 11 Apr 2008 10:04:23 +0000 (10:04 +0000)
zypp.conf
zypp/Locks.cc
zypp/Locks.h
zypp/ZConfig.cc
zypp/ZConfig.h
zypp/zypp_detail/ZYppImpl.cc

index 21fcb9f..945a9e1 100644 (file)
--- a/zypp.conf
+++ b/zypp.conf
 ## Valid values: boolean
 ## Default value: false
 ##
-# solver.onlyRequires = false
\ No newline at end of file
+# solver.onlyRequires = false
+
+##
+## Path to locks file. If not exist then is create.
+## In this file is saved also UI locks.
+##
+## valid value: path to file or place where file can be created
+## default value: /etc/zypp/locks
+##
+# locksfile.path = /etc/zypp/locks
+
+## 
+## Whetever to apply locks in locks file after zypp start.
+##
+## Valid values: boolean
+## Default value: true
+##
+# locksfile.apply = true
index 6fc404f..409b12a 100644 (file)
@@ -34,49 +34,6 @@ namespace zypp
 {
 namespace locks
 {
-//
-// assign Lock to installed pool item
-//
-
-struct AddLockToPool
-{
-  AddLockToPool( const ResPool &pool )
-  : _pool(pool)
-  , _count(0)
-  {
-
-  }
-
-  bool operator()( const std::string & str_r )
-  {
-#warning MUST FIX LOCK IMPLEMENTATION
-    // - make Capability's parse 'Name [Op edition]' available so it can be used here
-    // - provide new, or extend Capability::Matches, functor to allow pattern (glob/rx) matching
-    return false;
-  } // end operator()()
-
-  ResPool _pool;
-  int _count;
-};
-
-//
-// read 'locks' table, evaluate 'glob' column, assign locks to pool
-//
-int
-readLocks(const ResPool & pool, const Pathname &file )
-{
-  PathInfo lockrc( file );
-  if ( lockrc.isFile() )
-  {
-    MIL << "Reading " << lockrc << endl;
-    ifstream inp( file.c_str() );
-    AddLockToPool addlock(pool);
-    iostr::forEachLine( inp, addlock);
-    MIL << addlock._count << " locks." << endl;
-    return addlock._count;
-  }
-  return 0;
-}
 
 Locks& Locks::instance()
 {
index 93375de..d70db91 100644 (file)
@@ -11,9 +11,6 @@ namespace zypp
 {
   namespace locks
   {
-
-    int readLocks(const ResPool & pool, const Pathname &file );
-
     class Locks
     {
     public:
index 33c4da4..6302724 100644 (file)
@@ -148,6 +148,7 @@ namespace zypp
         , repo_refresh_delay           ( 10 )
         , download_use_patchrpm        ( true )
         , download_use_deltarpm        ( true )
+        , apply_locks_file              ( true )
        , solver_onlyRequires ( false )
 
       {
@@ -237,10 +238,14 @@ namespace zypp
                 {
                   solver_onlyRequires = str::strToBool( value, solver_onlyRequires );              
                 }              
-                else if ( entry == "locksfile" )
+                else if ( entry == "locksfile.path" )
                 {
                   locks_file = Pathname(value);
                 }
+                else if ( entry == "locksfile.apply" )
+                {
+                  apply_locks_file = str::strToBool( value, apply_locks_file );
+                }
               }
             }
           }
@@ -288,6 +293,8 @@ namespace zypp
 
     bool solver_onlyRequires; 
 
+    bool apply_locks_file;
+
   };
   ///////////////////////////////////////////////////////////////////
 
@@ -438,6 +445,11 @@ namespace zypp
         ? Pathname("/etc/zypp/locks") : _pimpl->locks_file );
   }
 
+  bool ZConfig::apply_locks_file() const
+  {
+    return _pimpl->apply_locks_file;
+  }
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index 70dba6d..b561576 100644 (file)
@@ -143,8 +143,16 @@ namespace zypp
        */      
       bool solver_onlyRequires() const;
 
+      /**
+       * Path where zypp can find or create lock file
+       */
       Pathname  locksFile() const;
 
+      /**
+       * Whetever locks file should be readed and applied after start
+       */
+      bool apply_locks_file() const;
+
     public:
       class Impl;
       /** Dtor */
index f204e17..9e8144b 100644 (file)
@@ -23,6 +23,9 @@
 #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"
 
 using std::endl;
 
@@ -176,32 +179,24 @@ namespace zypp
 
     int ZYppImpl::applyLocks()
     {
-#warning make the /etc/zypp/locks path an option zconfig.
-      Pathname locksrcPath( "/etc/zypp/locks" );
-      try
-      {
-        Target_Ptr trg( target() );
-        if ( trg )
-          locksrcPath = trg->root() / locksrcPath;
-      }
-      catch ( ... )
-      {
-        // noop: Someone decided to let target() throw if the ptr is NULL ;(
-      }
+      if (!ZConfig::instance().apply_locks_file())
+        return 0;
 
-      int num=0;
-      PathInfo locksrc( locksrcPath );
-      if ( locksrc.isFile() )
-      {
-        MIL << "Reading locks from '" << locksrcPath << "'" << endl;
-        num = zypp::locks::readLocks( pool(), locksrcPath );
-        MIL << num << " items locked." << endl;
-      }
-      else
+      //TODO catch posibble exceptions
+      locks::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())
       {
-        MIL << "No file '" << locksrcPath << "' to read locks from" << endl;
+        PoolItem i(*it);
+        if ( i.status().isLocked() )
+          count++;
       }
-      return num;
+
+      return count;
     }
     /******************************************************************
      **