- Implement a more efficient rpm cache based on micha and coolo's ideas
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 13 Feb 2008 15:07:14 +0000 (15:07 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 13 Feb 2008 15:07:14 +0000 (15:07 +0000)
- rename _rpm.solv to @System.solv (or whatever system repo name is)
- use the old solv to speedup rpmdb2solv (merge) if it is available

zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h

index e91b0a4c428f4bca9de2091dd6ddb705493217ca..171e622b5534676826190003d177a59d45684e1b 100644 (file)
@@ -26,6 +26,7 @@
 #include "zypp/PoolItem.h"
 #include "zypp/ResObjects.h"
 #include "zypp/Url.h"
+#include "zypp/TmpPath.h"
 #include "zypp/RepoStatus.h"
 #include "zypp/ExternalProgram.h"
 
@@ -291,15 +292,19 @@ namespace zypp
       MIL << "Targets closed" << endl;
     }
 
-    void TargetImpl::load()
+    
+    void TargetImpl::buildCache()
     {
-      Pathname rpmsolv = _root + ZConfig::instance().repoCachePath() + "_rpm.solv";
-      Pathname rpmsolvcookie = _root + ZConfig::instance().repoCachePath() + "_rpm.cookie";
+      Pathname base = _root + ZConfig::instance().repoCachePath() + sat::Pool::instance().systemRepoName();
+      Pathname rpmsolv = base.extend(".solv");
+      Pathname rpmsolvcookie = base.extend(".cookie");
+      
       bool build_rpm_solv = true;
       // lets see if the rpm solv cache exists
 
       RepoStatus rpmstatus(_root + "/var/lib/rpm/Name");
-      if ( PathInfo(rpmsolv).isExist() )
+      bool solvexisted = PathInfo(rpmsolv).isExist();
+      if ( solvexisted )
       {
         // see the status of the cache
         PathInfo cookie( rpmsolvcookie );
@@ -317,14 +322,24 @@ namespace zypp
 
       if ( build_rpm_solv )
       {
+        filesystem::TmpFile tmpsolv( _root + ZConfig::instance().repoCachePath() /*dir*/, 
+                                     sat::Pool::instance().systemRepoName() /* prefix */);
+        
          MIL << "Executing solv converter" << endl;
-         // Take care we unlink the solvfile on exception
-         ManagedFile guard( rpmsolv, filesystem::unlink );
-         ManagedFile guardcookie( rpmsolvcookie, filesystem::unlink );
 
 #warning FIXME add root to rpmdb2solv
         // FIXME add root to rpmdb2solv
-        string cmd( str::form( "rpmdb2solv > \"%s\"", rpmsolv.c_str() ) );
+        string cmd;
+        if ( solvexisted )
+        {
+          MIL << "Old cache found, using it to speed up (merge)" << endl;
+          cmd = str::form( "rpmdb2solv \"%s\" > \"%s\"", rpmsolv.c_str(), tmpsolv.path().c_str() );
+        }
+        else
+        {
+          cmd = str::form( "rpmdb2solv > \"%s\"", tmpsolv.path().c_str() );
+        }
+        
         ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
         for ( string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
           MIL << "  " << output;
@@ -333,13 +348,30 @@ namespace zypp
         if ( ret != 0 )
           ZYPP_THROW(Exception("Failed to cache rpm database"));
 
+        // Take care we unlink the solvfile on exception
+        ManagedFile guard( rpmsolv, filesystem::unlink );
+        ManagedFile guardcookie( rpmsolvcookie, filesystem::unlink );
+         
+        ret = filesystem::rename( tmpsolv, rpmsolv );
+        
+        if ( ret != 0 )
+          ZYPP_THROW(Exception("Failed to move cache to final destination"));
+        
         rpmstatus.saveToCookieFile(rpmsolvcookie);
 
         // We keep it.
         guard.resetDispose();
         guardcookie.resetDispose();
       }
-
+    }
+    
+    void TargetImpl::load()
+    {
+      Pathname base = _root + ZConfig::instance().repoCachePath() + sat::Pool::instance().systemRepoName();
+      Pathname rpmsolv = base.extend(".solv");
+      
+      buildCache();
+     
       //now add the repos to the pool
       MIL << "adding " << rpmsolv << " to pool(" << sat::Pool::instance().systemRepoName() << ")";
       sat::Repo system = sat::Pool::instance().reposInsert(sat::Pool::instance().systemRepoName());
index 10dc21db7538a9df6bff43a257134c7dce99e25b..512856b8a29c8cd6a86e02166a4ec0adc6841bd3 100644 (file)
@@ -69,6 +69,8 @@ namespace zypp
 
       void load();
 
+      void buildCache();
+      
     public:
 
       /** The root set for this target */