Imported Upstream version 14.47.1
[platform/upstream/libzypp.git] / zypp / sat / Pool.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.cc
10  *
11 */
12
13 #include <iostream>
14
15 #include "zypp/base/Easy.h"
16 #include "zypp/base/Logger.h"
17 #include "zypp/base/Gettext.h"
18 #include "zypp/base/Exception.h"
19
20 #include "zypp/AutoDispose.h"
21
22 #include "zypp/sat/detail/PoolImpl.h"
23 #include "zypp/sat/Pool.h"
24 #include "zypp/sat/LookupAttr.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29   ///////////////////////////////////////////////////////////////////
30   namespace sat
31   { /////////////////////////////////////////////////////////////////
32
33     const std::string & Pool::systemRepoAlias()
34     { return detail::PoolImpl::systemRepoAlias(); }
35
36     detail::CPool * Pool::get() const
37     { return myPool().getPool(); }
38
39     Pool::size_type Pool::capacity() const
40     { return myPool()->nsolvables; }
41
42     const SerialNumber & Pool::serial() const
43     { return myPool().serial(); }
44
45     void Pool::prepare() const
46     { return myPool().prepare(); }
47
48     void Pool::prepareForSolving() const
49     { return myPool().prepareForSolving(); }
50
51     Pathname Pool::rootDir() const
52     { return myPool().rootDir(); }
53
54     void Pool::rootDir( const Pathname & root_r )
55     { return myPool().rootDir( root_r ); }
56
57     bool Pool::reposEmpty() const
58     { return ! myPool()->urepos; }
59
60     Pool::size_type Pool::reposSize() const
61     { return myPool()->urepos; }
62
63     Pool::RepositoryIterator Pool::reposBegin() const
64     {
65       if ( myPool()->urepos )
66       { // repos[0] == NULL
67         for_( it, myPool()->repos+1, myPool()->repos+myPool()->nrepos )
68           if ( *it )
69             return RepositoryIterator( it );
70       }
71       return reposEnd();
72     }
73
74     Pool::RepositoryIterator Pool::reposEnd() const
75     { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
76
77     bool Pool::solvablesEmpty() const
78     {
79       // return myPool()->nsolvables;
80       // nsolvables is the array size including
81       // invalid Solvables.
82       for_( it, reposBegin(), reposEnd() )
83       {
84         if ( ! it->solvablesEmpty() )
85           return false;
86       }
87       return true;
88     }
89
90     Pool::size_type Pool::solvablesSize() const
91     {
92       // Do not return myPool()->nsolvables;
93       // nsolvables is the array size including
94       // invalid Solvables.
95       size_type ret = 0;
96       for_( it, reposBegin(), reposEnd() )
97       {
98         ret += it->solvablesSize();
99       }
100       return ret;
101     }
102
103     Pool::SolvableIterator Pool::solvablesBegin() const
104     { return SolvableIterator( myPool().getFirstId() ); }
105
106     Pool::SolvableIterator Pool::solvablesEnd() const
107     { return SolvableIterator(); }
108
109     Repository Pool::reposInsert( const std::string & alias_r )
110     {
111       Repository ret( reposFind( alias_r ) );
112       if ( ret )
113         return ret;
114
115       ret = Repository( myPool()._createRepo( alias_r ) );
116       if ( ret.isSystemRepo() )
117       {
118         // autoprovide (dummy) RepoInfo
119         RepoInfo info;
120         info.setAlias( alias_r );
121         info.setName( alias_r );
122         info.setAutorefresh( true );
123         info.setEnabled( true );
124         ret.setInfo( info );
125       }
126       return ret;
127     }
128
129     Repository Pool::reposFind( const std::string & alias_r ) const
130     {
131       for_( it, reposBegin(), reposEnd() )
132       {
133         if ( alias_r == it->alias() )
134           return *it;
135       }
136       return Repository();
137     }
138
139     Repository Pool::findSystemRepo() const
140     {
141       return Repository( myPool().systemRepo() );
142     }
143
144     Repository Pool::systemRepo()
145     {
146       if ( myPool().systemRepo() )
147         return Repository( myPool().systemRepo() );
148       return reposInsert( systemRepoAlias() );
149     }
150
151     Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
152     {
153       // Using a temporay repo! (The additional parenthesis are required.)
154       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
155       *tmprepo = reposInsert( alias_r );
156       tmprepo->addSolv( file_r );
157
158       // no exceptions so we keep it:
159       tmprepo.resetDispose();
160       return tmprepo;
161     }
162
163     Repository Pool::addRepoSolv( const Pathname & file_r )
164     { return addRepoSolv( file_r, file_r.basename() ); }
165
166     Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
167     {
168       Repository ret( addRepoSolv( file_r, info_r.alias() ) );
169       ret.setInfo( info_r );
170       return ret;
171     }
172
173     /////////////////////////////////////////////////////////////////
174
175     Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
176     {
177       // Using a temporay repo! (The additional parenthesis are required.)
178       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
179       *tmprepo = reposInsert( alias_r );
180       tmprepo->addHelix( file_r );
181
182       // no exceptions so we keep it:
183       tmprepo.resetDispose();
184       return tmprepo;
185     }
186
187     Repository Pool::addRepoHelix( const Pathname & file_r )
188     { return addRepoHelix( file_r, file_r.basename() ); }
189
190     Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
191     {
192       Repository ret( addRepoHelix( file_r, info_r.alias() ) );
193       ret.setInfo( info_r );
194       return ret;
195     }
196
197    /////////////////////////////////////////////////////////////////
198
199     void Pool::setTextLocale( const Locale & locale_r )
200     { myPool().setTextLocale( locale_r ); }
201
202     void Pool::setRequestedLocales( const LocaleSet & locales_r )
203     { myPool().setRequestedLocales( locales_r ); }
204
205     bool Pool::addRequestedLocale( const Locale & locale_r )
206     { return myPool().addRequestedLocale( locale_r ); }
207
208     bool Pool::eraseRequestedLocale( const Locale & locale_r )
209     { return myPool().eraseRequestedLocale( locale_r ); }
210
211     const LocaleSet & Pool::getRequestedLocales() const
212     { return myPool().getRequestedLocales(); }
213
214     bool Pool::isRequestedLocale( const Locale & locale_r ) const
215     { return myPool().isRequestedLocale( locale_r ); }
216
217     const LocaleSet & Pool::getAvailableLocales() const
218     {  return myPool().getAvailableLocales(); }
219
220     bool Pool::isAvailableLocale( const Locale & locale_r ) const
221     { return myPool().isAvailableLocale( locale_r ); }
222
223     bool Pool::multiversionEmpty() const                        { return myPool().multiversionList().empty(); }
224     size_t Pool::multiversionSize() const                       { return myPool().multiversionList().size(); }
225     Pool::MultiversionIterator Pool::multiversionBegin() const  { return myPool().multiversionList().begin(); }
226     Pool::MultiversionIterator Pool::multiversionEnd() const    { return myPool().multiversionList().end(); }
227     bool Pool::isMultiversion( IdString ident_r ) const         { return myPool().isMultiversion( ident_r ); }
228
229     Queue Pool::autoInstalled() const                           { return myPool().autoInstalled(); }
230     void Pool::setAutoInstalled( const Queue & autoInstalled_r ){ myPool().setAutoInstalled( autoInstalled_r ); }
231
232    /******************************************************************
233     **
234     **  FUNCTION NAME : operator<<
235     **  FUNCTION TYPE : std::ostream &
236     */
237     std::ostream & operator<<( std::ostream & str, const Pool & obj )
238     {
239       return str << "sat::pool(" << obj.serial() << ")["
240           << obj.capacity() << "]{"
241           << obj.reposSize() << "repos|"
242           << obj.solvablesSize() << "slov}";
243     }
244
245     /////////////////////////////////////////////////////////////////
246   } // namespace sat
247   ///////////////////////////////////////////////////////////////////
248   /////////////////////////////////////////////////////////////////
249 } // namespace zypp
250 ///////////////////////////////////////////////////////////////////