add applyLocks() to apply persistant locks before solving
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 9 Aug 2007 12:24:36 +0000 (12:24 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 9 Aug 2007 12:24:36 +0000 (12:24 +0000)
zypp/ZYpp.cc
zypp/ZYpp.h
zypp/zypp_detail/ZYppImpl.cc
zypp/zypp_detail/ZYppImpl.h

index 2076853..3a9d952 100644 (file)
@@ -146,6 +146,8 @@ namespace zypp
   void ZYpp::setHomePath( const Pathname & path )
   { _pimpl->setHomePath(path); }
 
+  int ZYpp::applyLocks()
+  { return _pimpl->applyLocks(); }
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index 6442d15..c4dcdfa 100644 (file)
@@ -174,6 +174,16 @@ namespace zypp
        won't be able to install incompatible packages ;-)   */
     void setArchitecture( const Arch & arch );
 
+  public:
+    
+   /** 
+    * \short Apply persistant locks to current pool.
+    * Call this before solving
+    *
+    * \returns Number of items locked
+    */
+   int applyLocks();
+      
   protected:
     /** Dtor */
     virtual ~ZYpp();
index 820d2d6..30f491b 100644 (file)
@@ -27,6 +27,7 @@
 #include "zypp/Language.h"
 #include "zypp/DiskUsageCounter.h"
 #include "zypp/NameKindProxy.h"
+#include "zypp/Locks.h"
 
 using std::endl;
 
@@ -399,6 +400,34 @@ namespace zypp
       return zypp_tmp_dir.path();
     }
 
+    int ZYppImpl::applyLocks()
+    {
+      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 ;(
+      }
+      
+      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
+      {
+        MIL << "No file '" << locksrcPath << "' to read locks from" << endl;
+      }
+      return num;
+    }
     /******************************************************************
      **
      **        FUNCTION NAME : operator<<
index 3643123..e8fdbd4 100644 (file)
@@ -146,6 +146,10 @@ namespace zypp
       void setPartitions(const DiskUsageCounter::MountPointSet &mp);
       DiskUsageCounter::MountPointSet getPartitions() const;
 
+    public:
+        
+      int applyLocks();
+      
     private:
       /** */
       ResPoolManager _pool;