1cf4950a645fdb2634cc6b37ea53f4cffb6f912a
[platform/upstream/libzypp.git] / zypp / repo / DeltaCandidates.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 extern "C"
10 {
11 #include <satsolver/knownid.h>
12 }
13
14 #include <iostream>
15 #include "zypp/base/Logger.h"
16 #include "zypp/Repository.h"
17 #include "zypp/repo/DeltaCandidates.h"
18 #include "zypp/sat/Pool.h"
19
20
21 using std::endl;
22 using namespace zypp::packagedelta;
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////
28   namespace repo
29   { /////////////////////////////////////////////////////////////////
30
31     /** DeltaCandidates implementation. */
32     struct DeltaCandidates::Impl
33     {
34       public:
35         Impl()
36         {}
37
38         Impl( const std::list<Repository> & repos, const std::string & pkgname = "" )
39         : repos(repos), pkgname(pkgname)
40         {}
41
42         std::list<Repository> repos;
43         std::string pkgname;
44
45       private:
46         friend Impl * rwcowClone<Impl>( const Impl * rhs );
47         /** clone for RWCOW_pointer */
48         Impl * clone() const
49         { return new Impl( *this ); }
50     };
51     ///////////////////////////////////////////////////////////////////
52
53     /** \relates DeltaCandidates::Impl Stream output */
54     inline std::ostream & operator<<( std::ostream & str, const DeltaCandidates::Impl & obj )
55     {
56       return str << "DeltaCandidates::Impl";
57     }
58
59     ///////////////////////////////////////////////////////////////////
60     //
61     // class DeltaCandidates
62     //
63     ///////////////////////////////////////////////////////////////////
64
65     DeltaCandidates::DeltaCandidates()
66     : _pimpl( new Impl )
67     {}
68
69
70     DeltaCandidates::DeltaCandidates(const std::list<Repository> & repos,
71                                      const std::string & pkgname)
72     : _pimpl( new Impl(repos, pkgname) )
73     {}
74
75     DeltaCandidates::~DeltaCandidates()
76     {}
77
78     std::list<DeltaRpm> DeltaCandidates::deltaRpms(const Package::constPtr & package) const
79     {
80       std::list<DeltaRpm> candidates;
81
82       DBG << "package: " << package << endl;
83       for_( rit, _pimpl->repos.begin(), _pimpl->repos.end() )
84       {
85         sat::LookupRepoAttr q( sat::SolvAttr::repositoryDeltaInfo, *rit );
86         for_( it, q.begin(), q.end() )
87         {
88           if ( _pimpl->pkgname.empty()
89                || it.subFind( sat::SolvAttr(DELTA_PACKAGE_NAME) ).asString() == _pimpl->pkgname )
90           {
91             DeltaRpm delta( it );
92             //DBG << "checking delta: " << delta << endl;
93             if ( ! package
94                    || (    package->name()    == delta.name()
95                         && package->edition() == delta.edition()
96                         && package->arch()    == delta.arch() ) )
97             {
98               DBG << "got delta candidate: " << delta << endl;
99               candidates.push_back( delta );
100             }
101           }
102         }
103       }
104       return candidates;
105     }
106
107     std::ostream & operator<<( std::ostream & str, const DeltaCandidates & obj )
108     {
109       return str << *obj._pimpl;
110     }
111
112     /////////////////////////////////////////////////////////////////
113   } // namespace repo
114   ///////////////////////////////////////////////////////////////////
115   /////////////////////////////////////////////////////////////////
116 } // namespace zypp
117 ///////////////////////////////////////////////////////////////////