From 7b626f4ed6e85364a61d13a10569e42500fa332c Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Mon, 19 May 2008 01:11:34 +0000 Subject: [PATCH] - delta support backup - limit delta candidates by package name - TODO: fix the deltainfo parser in sat (add missing stuff, check attributes), beautify --- devel/devel.jkupec/deltarpm.cc | 183 +++++++++++++++++++++++++++++++++++++++++ zypp/repo/DeltaCandidates.cc | 52 ++++++++---- zypp/repo/DeltaCandidates.h | 2 +- zypp/repo/PackageDelta.cc | 116 +++++++++++++++++++++++++- zypp/repo/PackageDelta.h | 24 +++--- zypp/target/TargetImpl.cc | 2 +- 6 files changed, 346 insertions(+), 33 deletions(-) create mode 100644 devel/devel.jkupec/deltarpm.cc diff --git a/devel/devel.jkupec/deltarpm.cc b/devel/devel.jkupec/deltarpm.cc new file mode 100644 index 0000000..5dae10e --- /dev/null +++ b/devel/devel.jkupec/deltarpm.cc @@ -0,0 +1,183 @@ +#include +#include +#include +#include + +extern "C" +{ +#include +} + +#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(pi.resolvable()); + + std::list repos( pool.reposBegin(), pool.reposEnd() ); + repo::DeltaCandidates deltas(repos, p->name()); + deltas.deltaRpms(p); + } + else + cout << "no such package" << endl; +} diff --git a/zypp/repo/DeltaCandidates.cc b/zypp/repo/DeltaCandidates.cc index 6a3f8b2..4200fa7 100644 --- a/zypp/repo/DeltaCandidates.cc +++ b/zypp/repo/DeltaCandidates.cc @@ -12,6 +12,11 @@ #include "zypp/Repository.h" #include "zypp/repo/DeltaCandidates.h" +extern "C" +{ +#include +} + using std::endl; using namespace zypp::packagedelta; @@ -28,8 +33,8 @@ namespace zypp public: - Impl( const std::list & repos ) - : repos(repos) + Impl( const std::list & repos, const std::string & pkgname = "" ) + : repos(repos), pkgname(pkgname) { } @@ -40,6 +45,7 @@ namespace zypp { return new Impl( *this ); } std::list repos; + std::string pkgname; }; /////////////////////////////////////////////////////////////////// @@ -49,8 +55,9 @@ namespace zypp return str << "DeltaCandidates::Impl"; } - DeltaCandidates::DeltaCandidates(const std::list & repos) - : _pimpl( new Impl(repos) ) + DeltaCandidates::DeltaCandidates(const std::list & 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 candidates_in_repo; // = (*it).patchRpms(); for ( std::list::const_iterator dit = candidates_in_repo.begin(); dit != candidates_in_repo.end(); @@ -88,27 +95,36 @@ namespace zypp { std::list candidates; +#warning deltaRpms are not completely implemented + // query all repos for ( std::list::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 candidates_in_repo; // = (*it).deltaRpms(); - for ( std::list::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; } diff --git a/zypp/repo/DeltaCandidates.h b/zypp/repo/DeltaCandidates.h index 6aa61df..70bb086 100644 --- a/zypp/repo/DeltaCandidates.h +++ b/zypp/repo/DeltaCandidates.h @@ -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 & repos ); + DeltaCandidates( const std::list & repos, const std::string & pkgname = "" ); /** Dtor */ ~DeltaCandidates(); diff --git a/zypp/repo/PackageDelta.cc b/zypp/repo/PackageDelta.cc index 0299b6c..1108566 100644 --- a/zypp/repo/PackageDelta.cc +++ b/zypp/repo/PackageDelta.cc @@ -10,12 +10,18 @@ * */ #include +extern "C" +{ +#include +} #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() << ')'; } diff --git a/zypp/repo/PackageDelta.h b/zypp/repo/PackageDelta.h index ecc0740..fde7bdd 100644 --- a/zypp/repo/PackageDelta.h +++ b/zypp/repo/PackageDelta.h @@ -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 BaseVersions; + //typedef std::list 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. */ diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 7667a2c..8584e7a 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -254,7 +254,7 @@ namespace zypp // Build a repository list for repos // contributing to the pool std::list 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(); } -- 2.7.4