5 #include <zypp/base/PtrTypes.h>
6 #include <zypp/base/Exception.h>
7 #include <zypp/base/ProvideNumericId.h>
9 #include "zypp/ZYppFactory.h"
10 #include "zypp/ResPoolProxy.h"
11 #include <zypp/SourceManager.h>
12 #include <zypp/SourceFactory.h>
14 #include "zypp/NVRAD.h"
15 #include "zypp/ResPool.h"
16 #include "zypp/ResFilters.h"
17 #include "zypp/CapFilters.h"
18 #include "zypp/Package.h"
19 #include "zypp/Language.h"
20 #include "zypp/NameKindProxy.h"
25 using namespace zypp::ui;
26 using namespace zypp::functor;
28 ///////////////////////////////////////////////////////////////////
30 static const Pathname sysRoot( "/Local/ROOT" );
32 ///////////////////////////////////////////////////////////////////
37 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
38 { return cont.find( val ) != cont.end(); }
41 ///////////////////////////////////////////////////////////////////
43 template<class _Condition>
46 SetTrue( _Condition cond_r )
51 bool operator()( _Tp t ) const
60 template<class _Condition>
61 inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
63 return SetTrue<_Condition>( cond_r );
66 template <class _Iterator, class _Filter, class _Function>
67 inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
71 for ( _Iterator it = begin_r; it != end_r; ++it )
73 if ( filter_r( *it ) )
83 void operator()( const PoolItem & pi ) const
85 USR << "S" << pi->source().numericId()
86 << "/M" << mediaId(pi)
89 unsigned mediaId( const PoolItem & pi ) const
91 Package::constPtr pkg( asKind<Package>(pi.resolvable()) );
93 return pkg->mediaId();
98 template <class _Iterator>
99 std::ostream & vdumpPoolStats( std::ostream & str,
100 _Iterator begin_r, _Iterator end_r )
102 pool::PoolStats stats;
103 std::for_each( begin_r, end_r,
105 functor::chain( setTrue_c(PrintPoolItem()),
106 setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
112 struct PoolItemSelect
114 void operator()( const PoolItem & pi ) const
116 if ( pi->source().numericId() == 2 )
117 pi.status().setTransact( true, ResStatus::USER );
121 ///////////////////////////////////////////////////////////////////
122 typedef std::list<PoolItem> PoolItemList;
123 typedef std::set<PoolItem> PoolItemSet;
124 #include "zypp/solver/detail/InstallOrder.h"
125 using zypp::solver::detail::InstallOrder;
128 ///////////////////////////////////////////////////////////////////
131 struct CollectTransacting
133 typedef std::list<PoolItem> PoolItemList;
135 void operator()( const PoolItem & pi )
137 if ( pi.status().isToBeInstalled() )
139 _toInstall.insert( pi );
141 else if ( pi.status().isToBeUninstalled() )
143 if ( pi.status().isToBeUninstalledDueToObsolete()
144 || pi.status().isToBeUninstalledDueToUpgrade() )
145 _skipToDelete.insert( pi );
147 _toDelete.insert( pi );
151 PoolItemSet _toInstall;
152 PoolItemSet _toDelete;
153 PoolItemSet _skipToDelete;
156 std::ostream & operator<<( std::ostream & str, const CollectTransacting & obj )
158 str << "CollectTransacting:" << endl;
159 dumpPoolStats( str << " toInstall: ",
160 obj._toInstall.begin(), obj._toInstall.end() ) << endl;
161 dumpPoolStats( str << " toDelete: ",
162 obj._toDelete.begin(), obj._toDelete.end() ) << endl;
163 dumpPoolStats( str << " skipToDelete: ",
164 obj._skipToDelete.begin(), obj._skipToDelete.end() ) << endl;
169 ///////////////////////////////////////////////////////////////////
171 template<class _InstIterator, class _DelIterator, class _OutputIterator>
172 void strip_obsoleted_to_delete( _InstIterator instBegin_r, _InstIterator instEnd_r,
173 _DelIterator delBegin_r, _DelIterator delEnd_r,
174 _OutputIterator skip_r )
176 if ( instBegin_r == instEnd_r
177 || delBegin_r == delEnd_r )
178 return; // ---> nothing to do
180 // build obsoletes from inst
182 for ( /**/; instBegin_r != instEnd_r; ++instBegin_r )
185 //PoolItem_Ref item( *it );
186 //obsoletes.insert( item->dep(Dep::OBSOLETES).begin(), item->dep(Dep::OBSOLETES).end() );
188 if ( obsoletes.size() == 0 )
189 return; // ---> nothing to do
192 PoolItemList undelayed;
193 // forall applDelete Packages...
194 for ( PoolItemList::iterator it = deleteList_r.begin();
195 it != deleteList_r.end(); ++it )
197 PoolItem_Ref ipkg( *it );
198 bool delayPkg = false;
199 // ...check whether an obsoletes....
200 for ( CapSet::iterator obs = obsoletes.begin();
201 ! delayPkg && obs != obsoletes.end(); ++obs )
203 // ...matches anything provided by the package?
204 for ( CapSet::const_iterator prov = ipkg->dep(Dep::PROVIDES).begin();
205 prov != ipkg->dep(Dep::PROVIDES).end(); ++prov )
207 if ( obs->matches( *prov ) == CapMatch::yes )
209 // if so, delay package deletion
210 DBG << "Ignore appl_delete (should be obsoleted): " << ipkg << endl;
212 ipkg.status().setTransact( false, ResStatus::USER );
218 DBG << "undelayed " << ipkg << endl;
219 undelayed.push_back( ipkg );
223 deleteList_r.swap( undelayed );
227 ///////////////////////////////////////////////////////////////////
229 struct SetTransactValue
231 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
232 : _newVal( newVal_r )
233 , _causer( causer_r )
236 ResStatus::TransactValue _newVal;
237 ResStatus::TransactByValue _causer;
239 bool operator()( const PoolItem & pi ) const
240 { return pi.status().setTransactValue( _newVal, _causer ); }
243 struct StatusReset : public SetTransactValue
246 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
251 inline bool selectForTransact( const NameKindProxy & nkp )
253 if ( nkp.availableEmpty() )
256 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
259 /******************************************************************
261 ** FUNCTION NAME : main
262 ** FUNCTION TYPE : int
264 int main( int argc, char * argv[] )
266 //zypp::base::LogControl::instance().logfile( "xxx" );
267 INT << "===[START]==========================================" << endl;
269 ResPool pool( getZYpp()->pool() );
271 getZYpp()->initTarget( sysRoot );
272 getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true );
273 INT << "Added target: " << pool << endl;
275 Source_Ref src1( createSource( "dir:/mounts/machcd2/CDs/SLES-10-CD-i386-Beta10/CD1" ) );
276 Source_Ref src2( createSource( "dir:/mounts/machcd2/kukuk/sles10-sp-i386/CD1" ) );
277 getZYpp()->addResolvables( src1.resolvables() );
278 getZYpp()->addResolvables( src2.resolvables() );
279 INT << "Pool: " << pool << endl;
281 selectForTransact( nameKindProxy<Pattern>( pool, "default" ) );
282 selectForTransact( nameKindProxy<Pattern>( pool, "x11" ) );
283 selectForTransact( nameKindProxy<Pattern>( pool, "kde" ) );
284 selectForTransact( nameKindProxy<Pattern>( pool, "OOo" ) );
286 vdumpPoolStats( INT << "Transacting: ",
287 make_filter_begin<resfilter::ByTransact>(pool),
288 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
292 zypp::base::LogControl::TmpLineWriter shutUp;
293 eres = getZYpp()->resolver()->establishPool();
294 rres = getZYpp()->resolver()->resolvePool();
296 MIL << "est " << eres << " slv " << rres << endl;
298 vdumpPoolStats( INT << "Transacting: ",
299 make_filter_begin<resfilter::ByTransact>(pool),
300 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
303 ZYppCommitPolicy policy;
304 policy.rpmNoSignature();
307 ZYppCommitResult res( getZYpp()->commit( policy ) );
311 for ( unsigned mnr = 1; mnr < 6; ++mnr )
313 policy.restrictToMedia( mnr );
314 ZYppCommitResult res( getZYpp()->commit( policy ) );
318 INT << "===[END]============================================" << endl << endl;