added preliminary commit function for target
authorJiri Srain <jsrain@suse.cz>
Mon, 30 Jan 2006 07:57:37 +0000 (07:57 +0000)
committerJiri Srain <jsrain@suse.cz>
Mon, 30 Jan 2006 07:57:37 +0000 (07:57 +0000)
zypp/Target.cc
zypp/Target.h
zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h

index abdc614..c0f6e51 100644 (file)
@@ -70,6 +70,9 @@ namespace zypp
   target::rpm::RpmDb & Target::rpmDb()
   { return _pimpl->rpm(); }
 
+  void Target::commit(ResPool & pool_r)
+  { return _pimpl->commit(pool_r); }
+
   std::ostream & Target::dumpOn( std::ostream & str ) const
   { return _pimpl->dumpOn( str ); }
 
index 38aff03..45d6686 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "zypp/ResStore.h"
 #include "zypp/Pathname.h"
-#include "zypp/target/TargetImpl.h"
+#include "zypp/ResPool.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -53,11 +53,13 @@ namespace zypp
     static Target_Ptr nullimpl();
     /** Refference to the RPM database */
     target::rpm::RpmDb & rpmDb();
+    /** Comomit changes in the pool */
+    void commit(ResPool & pool_r);
 
   public:
-    /** Factory ctor */
+    /** Ctor */
     Target( const Pathname & root = "/" );
-    /** Factory ctor */
+    /** Ctor */
     explicit
     Target( const Impl_Ptr & impl_r );
 
index 279dadd..2b4be7d 100644 (file)
@@ -14,7 +14,9 @@
 
 #include "zypp/target/TargetImpl.h"
 
-using std::endl;
+#include <vector>
+
+using namespace std;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -74,6 +76,48 @@ namespace zypp
       return _store;
     }
 
+    void TargetImpl::commit(ResPool & pool_r)
+    {
+#warning FIXME this orderding doesn't honor the dependencies
+      vector<ResObject::constPtr> to_uninstall;
+      vector<ResObject::constPtr> to_install;
+      for (ResPool::const_iterator it = pool_r.begin();
+           it != pool_r.end(); it++)
+      {
+       if (it->status().isToBeInstalled())
+       {
+         to_install.push_back(it->resolvable());
+       }
+       else if (it->status().isToBeUninstalled())
+       {
+         to_uninstall.push_back(it->resolvable());
+       }
+      }
+      // first uninstall what is to be uninstalled
+      for (vector<ResObject::constPtr>::const_iterator it = to_uninstall.begin();
+           it != to_uninstall.end();
+          it++)
+      {
+       if (isKind<Package>(*it))
+       {
+         Package::constPtr p = dynamic_pointer_cast<const Package>(*it);
+         rpm().removePackage(p);
+       }
+#warning FIXME other resolvables (once more below)
+      }
+      // now install what is to be installed
+      for (vector<ResObject::constPtr>::const_iterator it = to_install.begin();
+           it != to_install.end();
+          it++)
+      {
+       if (isKind<Package>(*it))
+       {
+         Package::constPtr p = dynamic_pointer_cast<const Package>(*it);
+         rpm().installPackage(p->getPlainRpm(), rpm::RpmDb::RPMINST_NOUPGRADE);
+       }
+      }
+    }
+
     rpm::RpmDb & TargetImpl::rpm()
     { return _rpm; }
 
index ee63bbb..3167ce8 100644 (file)
@@ -60,6 +60,10 @@ namespace zypp
       /** All resolvables in the target. */
       const ResStore & resolvables();
 
+      /** Comomit changes in the pool */
+#warning Add support for multiple medias - eg. limit only to CD1
+      void commit(ResPool & pool_r);
+
       /** Overload to realize stream output. */
       virtual std::ostream & dumpOn( std::ostream & str ) const
       { return str << "TargetImpl"; }