4 #include "zypp/base/Exception.h"
5 #include "zypp/base/InputStream.h"
6 #include "zypp/base/DefaultIntegral.h"
7 #include <zypp/base/Function.h>
8 #include <zypp/base/Iterator.h>
10 #include <zypp/SourceManager.h>
11 #include <zypp/SourceFactory.h>
12 #include "zypp/ZYppCallbacks.h"
14 #include "zypp/NVRAD.h"
15 #include "zypp/ResFilters.h"
16 #include "zypp/CapFilters.h"
17 #include "zypp/PackageKeyword.h"
18 #include "zypp/pool/GetResolvablesToInsDel.h"
23 ///////////////////////////////////////////////////////////////////
25 struct SetTransactValue
27 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
32 ResStatus::TransactValue _newVal;
33 ResStatus::TransactByValue _causer;
35 bool operator()( const PoolItem & pi ) const
37 bool ret = pi.status().setTransactValue( _newVal, _causer );
39 ERR << _newVal << _causer << " " << pi << endl;
44 struct StatusReset : public SetTransactValue
47 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
51 struct StatusInstall : public SetTransactValue
54 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
58 inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
60 if ( nkp.availableEmpty() )
62 ERR << "No Item to select: " << nkp << endl;
64 ZYPP_THROW( Exception("No Item to select") );
69 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
70 for ( ; it != nkp.availableEnd(); ++it )
72 if ( (*it)->arch() == arch )
73 return (*it).status().setTransact( true, ResStatus::USER );
77 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
80 ///////////////////////////////////////////////////////////////////
82 bool solve( bool establish = false )
86 bool eres = getZYpp()->resolver()->establishPool();
89 ERR << "establish " << eres << endl;
92 MIL << "establish " << eres << endl;
95 bool rres = getZYpp()->resolver()->resolvePool();
98 ERR << "resolve " << rres << endl;
101 MIL << "resolve " << rres << endl;
105 ///////////////////////////////////////////////////////////////////
107 /******************************************************************
109 ** FUNCTION NAME : main
110 ** FUNCTION TYPE : int
112 int main( int argc, char * argv[] )
114 INT << "===[START]==========================================" << endl;
115 ///////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////
120 const char * data[] = {
123 "- prodold 1 1 x86_64",
125 "- prodnew 1 1 x86_64",
130 debug::addPool( data, data + ( sizeof(data) / sizeof(const char *) ) );
134 debug::addPool( "SRC/iorderbug.pool" );
136 ResPool pool( getZYpp()->pool() );
137 vdumpPoolStats( USR << "Initial pool:" << endl,
139 pool.end() ) << endl;
141 ///////////////////////////////////////////////////////////////////
142 // define transaction
143 ///////////////////////////////////////////////////////////////////
145 for_each( pool.byKindBegin<Product>(), pool.byKindEnd<Product>(), StatusInstall() );
147 #define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
148 selt( Package, bash );
149 selt( Package, readline );
150 selt( Package, fontcfg );
153 ///////////////////////////////////////////////////////////////////
155 ///////////////////////////////////////////////////////////////////
161 vdumpPoolStats( USR << "Transacting:"<< endl,
162 make_filter_begin<resfilter::ByTransact>(pool),
163 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
165 ///////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////
168 pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
169 MIL << "GetResolvablesToInsDel:" << endl << collect << endl;
173 // Collect until the 1st package from an unwanted media occurs.
174 // Further collection could violate install order.
175 bool hitUnwantedMedia = false;
176 typedef pool::GetResolvablesToInsDel::PoolItemList PoolItemList;
177 PoolItemList::iterator fst=collect._toInstall.end();
178 for ( PoolItemList::iterator it = collect._toInstall.begin(); it != collect._toInstall.end(); ++it)
180 ResObject::constPtr res( it->resolvable() );
182 if ( hitUnwantedMedia
183 || ( res->sourceMediaNr() && res->sourceMediaNr() != 1 ) )
185 if ( !hitUnwantedMedia )
187 hitUnwantedMedia = true;
193 dumpRange( WAR << "toInstall1: " << endl,
194 collect._toInstall.begin(), fst ) << endl;
195 dumpRange( WAR << "toInstall2: " << endl,
196 fst, collect._toInstall.end() ) << endl;
197 dumpRange( ERR << "toDelete: " << endl,
198 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
202 dumpRange( WAR << "toInstall: " << endl,
203 collect._toInstall.begin(), collect._toInstall.end() ) << endl;
204 dumpRange( ERR << "toDelete: " << endl,
205 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
208 INT << "===[END]============================================" << endl << endl;
209 zypp::base::LogControl::instance().logNothing();