- delta support backup
authorJan Kupec <jkupec@suse.cz>
Mon, 19 May 2008 01:11:34 +0000 (01:11 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 19 May 2008 01:11:34 +0000 (01:11 +0000)
- limit delta candidates by package name
- TODO: fix the deltainfo parser in sat (add missing stuff, check
  attributes), beautify

devel/devel.jkupec/deltarpm.cc [new file with mode: 0644]
zypp/repo/DeltaCandidates.cc
zypp/repo/DeltaCandidates.h
zypp/repo/PackageDelta.cc
zypp/repo/PackageDelta.h
zypp/target/TargetImpl.cc

diff --git a/devel/devel.jkupec/deltarpm.cc b/devel/devel.jkupec/deltarpm.cc
new file mode 100644 (file)
index 0000000..5dae10e
--- /dev/null
@@ -0,0 +1,183 @@
+#include <stdio.h>
+#include <iostream>
+#include <iterator>
+#include <list>
+
+extern "C"
+{
+#include <satsolver/repo.h>
+}
+
+#include "zypp/ZYppFactory.h"
+#include "zypp/Pathname.h"
+
+#include "zypp/RepoManager.h"
+#include "zypp/repo/DeltaCandidates.h"
+#include "zypp/PoolQuery.h"
+
+using std::cout;
+using std::endl;
+using std::string;
+using namespace zypp;
+
+
+struct PrintAndCount
+{
+  PrintAndCount() : _count(0) {}
+
+  bool operator()( const sat::Solvable & solvable )
+  {
+    zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) );
+    cout << pi.resolvable() << endl;
+    // name: yast2-sound 2.16.2-9 i586
+    ++_count;
+    return true;
+  }
+
+  unsigned _count;
+};
+
+
+
+int main (int argc, const char ** argv)
+{
+  Pathname rootdir(SRC_DIR "/data/deltarpm");
+  RepoManagerOptions opts(rootdir);
+  opts.repoRawCachePath = rootdir;
+  opts.repoSolvCachePath = rootdir;
+  RepoManager rm(opts);
+
+  RepoInfo updates;
+  updates.setAlias("updates");
+  updates.addBaseUrl(Url(string("dir:") + rootdir.absolutename().asString() + "/updates"));
+
+  RepoInfo updates2;
+  updates2.setAlias("updates2");
+  updates2.addBaseUrl(Url(string("dir:") + rootdir.absolutename().asString() + "/updates2"));
+
+  try
+  {
+    rm.buildCache(updates);
+    rm.buildCache(updates2);
+    rm.loadFromCache(updates);
+    rm.loadFromCache(updates2);
+  }
+  catch (const Exception & e)
+  {
+    cout << "Problem getting the data: " << e.msg() << endl;
+  }
+
+  sat::Pool pool(sat::Pool::instance());
+  for_(repoit, pool.reposBegin(), pool.reposEnd())
+  {
+    Repository repo(*repoit);
+    for (int i = 0; i < repo.get()->nextra; ++i)
+    {
+      cout << endl << "extra " << i << ":" << endl;
+      ::Dataiterator di;
+      ::dataiterator_init(&di, repo.get(), -1 - i, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
+      while (::dataiterator_step(&di))
+      {
+        const char * keyname;
+        keyname = ::id2str(repo.get()->pool, di.key->name);
+        
+        cout << keyname << ": ";
+
+        switch (di.key->name)
+        {
+        case DELTA_PACKAGE_NAME:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        /*
+        case DELTA_PACKAGE_EVR:
+        {
+          if (di.key->type == REPOKEY_TYPE_STR)
+            cout << di.kv.str;
+          else
+            cout << "...";
+          break;
+        }
+        case DELTA_PACKAGE_ARCH:
+        {
+          break;
+        }
+        */
+        case DELTA_LOCATION_DIR:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_LOCATION_NAME:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_LOCATION_EVR:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_LOCATION_SUFFIX:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_DOWNLOADSIZE:
+        {
+          cout << di.kv.num;
+          break;
+        }
+        case DELTA_CHECKSUM:
+        {
+          cout << di.kv.str;
+          break;
+        }
+        case DELTA_BASE_EVR:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_SEQ_NAME:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_SEQ_EVR:
+        {
+          cout << IdString(di.kv.id);
+          break;
+        }
+        case DELTA_SEQ_NUM:
+        {
+          cout << di.kv.str;
+          break;
+        }
+        default:
+          cout << "ingoring " << IdString(di.key->name) << endl;
+        }
+        cout << endl;
+      }
+    }
+  }
+
+  PoolQuery q;
+  q.addKind(ResKind::package);
+  q.addAttribute(sat::SolvAttr::name, "libzypp");
+  q.setMatchExact();
+  
+  std::for_each(q.begin(), q.end(), PrintAndCount());
+
+  PoolItem pi(*q.poolItemBegin());
+  if (pi)
+  {
+    Package::constPtr p = asKind<Package>(pi.resolvable());
+
+    std::list<Repository> repos( pool.reposBegin(), pool.reposEnd() );
+    repo::DeltaCandidates deltas(repos, p->name());
+    deltas.deltaRpms(p);
+  }
+  else
+    cout << "no such package" << endl;
+}
index 6a3f8b2..4200fa7 100644 (file)
 #include "zypp/Repository.h"
 #include "zypp/repo/DeltaCandidates.h"
 
+extern "C"
+{
+#include <satsolver/repo.h>
+}
+
 using std::endl;
 using namespace zypp::packagedelta;
 
@@ -28,8 +33,8 @@ namespace zypp
 
     public:
 
-      Impl( const std::list<Repository> & repos )
-        : repos(repos)
+      Impl( const std::list<Repository> & repos, const std::string & pkgname = "" )
+        : repos(repos), pkgname(pkgname)
       {
 
       }
@@ -40,6 +45,7 @@ namespace zypp
       { return new Impl( *this ); }
 
       std::list<Repository> repos;
+      std::string pkgname;
     };
     ///////////////////////////////////////////////////////////////////
 
@@ -49,8 +55,9 @@ namespace zypp
       return str << "DeltaCandidates::Impl";
     }
 
-    DeltaCandidates::DeltaCandidates(const std::list<Repository> & repos)
-    : _pimpl( new Impl(repos) )
+    DeltaCandidates::DeltaCandidates(const std::list<Repository> & repos,
+                                     const std::string & pkgname)
+    : _pimpl( new Impl(repos, pkgname) )
     {}
 
     DeltaCandidates::~DeltaCandidates()
@@ -66,7 +73,7 @@ namespace zypp
             ++it )
       {
         // all delta in repo
-       #warning patchRpms are not implemented
+       #warning patchRpms are not implemented
        std::list<PatchRpm> candidates_in_repo; // = (*it).patchRpms();
         for ( std::list<PatchRpm>::const_iterator dit = candidates_in_repo.begin();
               dit != candidates_in_repo.end();
@@ -88,27 +95,36 @@ namespace zypp
     {
       std::list<DeltaRpm> candidates;
 
+#warning deltaRpms are not completely implemented
+
       // query all repos
       for ( std::list<Repository>::const_iterator it = _pimpl->repos.begin();
-            it != _pimpl->repos.end();
-            ++it )
+            it != _pimpl->repos.end(); ++it )
       {
-        // all delta in repo
-       #warning deltaRpms are not implemented
-       std::list<DeltaRpm> candidates_in_repo; // = (*it).deltaRpms();
-        for ( std::list<DeltaRpm>::const_iterator dit = candidates_in_repo.begin();
-              dit != candidates_in_repo.end();
-              ++dit )
+        for (int i = 0; i < it->get()->nextra; ++i)
         {
-           if ( ! package
-               || (    package->name()    == dit->name()
-                    && package->edition() == dit->edition()
-                    && package->arch()    == dit->arch() ) )
+          ::Dataiterator di;
+          ::dataiterator_init(&di
+            , it->get()                                              // in this repo
+            , -1 - i                                                 // in this extra
+            , DELTA_PACKAGE_NAME                                     // with this attribute
+            , _pimpl->pkgname.empty() ? 0 : _pimpl->pkgname.c_str()  // of this value
+            , SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE | SEARCH_STRING);
+          while (::dataiterator_step(&di))
           {
-            candidates.push_back( *dit );
+            DeltaRpm delta(*it, di.solvid);
+            std::cout << delta << endl;
+            if ( ! package
+                || (    package->name()    == delta.name()
+                     && package->edition() == delta.edition()
+                     && package->arch()    == delta.arch() ) )
+            {
+              candidates.push_back( delta );
+            }
           }
         }
       }
+
       return candidates;
     }
 
index 6aa61df..70bb086 100644 (file)
@@ -47,7 +47,7 @@ namespace zypp
        * \param repos Set of repositories providing patch and delta packages
        * \param installed_callback Will be used to ask if a package is installed or not
        */
-      DeltaCandidates( const std::list<Repository> & repos );
+      DeltaCandidates( const std::list<Repository> & repos, const std::string & pkgname = "" );
       /** Dtor */
       ~DeltaCandidates();
 
index 0299b6c..1108566 100644 (file)
  *
 */
 #include <iostream>
+extern "C"
+{
+#include <satsolver/repo.h>
+}
 
 #include "zypp/base/LogTools.h"
 
 #include "zypp/repo/PackageDelta.h"
 
+
 using std::endl;
+using std::string;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -36,15 +42,119 @@ namespace zypp
       << ')';
     }
 
+    DeltaRpm::DeltaRpm(const Repository & repo, sat::detail::IdType extraid)
+    {
+      MIL << "creating deltarpm from repo " << repo.name() << ", id " << extraid << endl;
+      ::Dataiterator di;
+      ::dataiterator_init(&di, repo.get(), extraid, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
+
+      string locdir;
+      string locname;
+      string locevr;
+      string locsuffix;
+      OnMediaLocation loc;
+      BaseVersion base;
+      string seqname;
+      string seqevr;
+      string seqnum;
+
+      if (::dataiterator_step(&di))
+      {
+        do
+        {
+          switch (di.key->name)
+          {
+          case DELTA_PACKAGE_NAME:
+          {
+            setName(IdString(di.kv.id).asString());
+            break;
+          }
+          /* \todo add this to the deltainfo parser in sat
+          case DELTA_PACKAGE_EVR:
+          {
+            setEdition(Edition(di.kv.str));
+            break;
+          }
+          case DELTA_PACKAGE_ARCH:
+          {
+            setArch(Arch(di.kv.str));
+            break;
+          }
+          */
+          case DELTA_LOCATION_DIR:
+          {
+            locdir = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_LOCATION_NAME:
+          {
+            locname = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_LOCATION_EVR:
+          {
+            locevr = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_LOCATION_SUFFIX:
+          {
+            locsuffix = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_DOWNLOADSIZE:
+          {
+            loc.setDownloadSize(di.kv.num);
+            break;
+          }
+          case DELTA_CHECKSUM:
+          {
+            loc.setChecksum(CheckSum::sha1(di.kv.str));
+            break;
+          }
+          case DELTA_BASE_EVR:
+          {
+            base.setEdition(Edition(IdString(di.kv.id).asString()));
+            break;
+          }
+          case DELTA_SEQ_NAME:
+          {
+            seqname = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_SEQ_EVR:
+          {
+            seqevr = IdString(di.kv.id).asString();
+            break;
+          }
+          case DELTA_SEQ_NUM:
+          {
+            seqnum = di.kv.str;
+            break;
+          }
+          default:
+            WAR << "ingoring unknown attribute: " << IdString(di.key->name) << endl;
+          }
+        } while (::dataiterator_step(&di));
+      }
+      else
+        ERR << "the extra does not exist in the repo" << endl;
+
+      //! \todo FIXME here + in sat tools
+      loc.setLocation(locdir + "/" + locname + "-" + locevr + "." + locsuffix); 
+      setLocation(loc);
+      base.setSequenceinfo(seqname + "-" + seqevr + "-" + seqnum);
+      setBaseversion(base);
+    }
+
     std::ostream & operator<<( std::ostream & str, const DeltaRpm & obj )
     {
       return str
       << "DeltaRpm[" << obj.name() << "-" << obj.edition() << "." << obj.arch()
       << "](" << obj.location()
-      << '|' << obj.buildtime()
+      //<< '|' << obj.buildtime()
       << '|' << obj.baseversion().edition()
-      << ',' << obj.baseversion().buildtime()
-      << ',' << obj.baseversion().checksum()
+      //<< ',' << obj.baseversion().buildtime()
+      //<< ',' << obj.baseversion().checksum()
       << ',' << obj.baseversion().sequenceinfo()
       << ')';
     }
index ecc0740..fde7bdd 100644 (file)
@@ -20,6 +20,9 @@
 #include "zypp/Arch.h"
 #include "zypp/Date.h"
 
+#include "zypp/sat/detail/PoolMember.h"
+#include "zypp/Repository.h"
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -86,28 +89,29 @@ namespace zypp
 
       public:
         const Edition &     edition()      const { return _edition; }
-        const Date &        buildtime()    const { return _buildtime; }
-        const CheckSum &    checksum()     const { return _checksum; }
+        //const Date &        buildtime()    const { return _buildtime; }
+        //const CheckSum &    checksum()     const { return _checksum; }
         const std::string & sequenceinfo() const { return _sequenceinfo; }
 
       public:
         BaseVersion & setEdition( const Edition & val_r )          { _edition = val_r; return *this; }
-        BaseVersion & setBuildtime( const Date & val_r )           { _buildtime = val_r; return *this; }
-        BaseVersion & setChecksum( const CheckSum & val_r )        { _checksum = val_r; return *this; }
+        //BaseVersion & setBuildtime( const Date & val_r )           { _buildtime = val_r; return *this; }
+        //BaseVersion & setChecksum( const CheckSum & val_r )        { _checksum = val_r; return *this; }
         BaseVersion & setSequenceinfo( const std::string & val_r ) { _sequenceinfo = val_r; return *this; }
 
       private:
         Edition     _edition;
-        Date        _buildtime;
-        CheckSum    _checksum;
+        //Date        _buildtime;
+        //CheckSum    _checksum;
         std::string _sequenceinfo;
       };
 
-      typedef std::list<BaseVersion> BaseVersions;
+      //typedef std::list<BaseVersion> BaseVersions;
 
     public:
       DeltaRpm()
       {}
+      DeltaRpm(const Repository & repo, sat::detail::IdType id);
 
     public:
       /** \name Target package ident. */
@@ -118,7 +122,7 @@ namespace zypp
       //@}
       const OnMediaLocation & location()     const { return _location; }
       const BaseVersion &     baseversion()  const { return _baseversion; }
-      const Date &            buildtime()    const { return _buildtime;}
+      //const Date &            buildtime()    const { return _buildtime;}
 
     public:
       DeltaRpm & setName( const std::string & val_r )         { _name = val_r; return *this; }
@@ -126,7 +130,7 @@ namespace zypp
       DeltaRpm & setArch( const Arch & val_r )                { _arch = val_r; return *this; }
       DeltaRpm & setLocation( const OnMediaLocation & val_r ) { _location = val_r; return *this; }
       DeltaRpm & setBaseversion( const BaseVersion & val_r )  { _baseversion = val_r; return *this; }
-      DeltaRpm & setBuildtime( const Date & val_r )           { _buildtime = val_r; return *this; }
+      //DeltaRpm & setBuildtime( const Date & val_r )           { _buildtime = val_r; return *this; }
 
     private:
       std::string     _name;
@@ -134,7 +138,7 @@ namespace zypp
       Arch            _arch;
       OnMediaLocation _location;
       BaseVersion     _baseversion;
-      Date            _buildtime;
+      //Date            _buildtime;
     };
 
     /** \relates DeltaRpm Stream output. */
index 7667a2c..8584e7a 100644 (file)
@@ -254,7 +254,7 @@ namespace zypp
         // Build a repository list for repos
         // contributing to the pool
         std::list<Repository> repos( _pool.knownRepositoriesBegin(), _pool.knownRepositoriesEnd() );
-        repo::DeltaCandidates deltas(repos);
+        repo::DeltaCandidates deltas(repos, p->name());
         repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
         return pkgProvider.providePackage();
       }