#include "zypp/base/Algorithm.h"
#include "zypp/base/Function.h"
#include "zypp/base/Functional.h"
+#include "zypp/base/IOStream.h"
#include "zypp/base/String.h"
+#include "zypp/ZYppFactory.h"
#include "zypp/ResPool.h"
+#include "zypp/ResPoolProxy.h"
+#include "zypp/NameKindProxy.h"
#include "zypp/CapFactory.h"
#include "zypp/Atom.h"
#include "zypp/Script.h"
#include "zypp/Message.h"
#include "zypp/Language.h"
+#include "zypp/VendorAttr.h"
///////////////////////////////////////////////////////////////////
namespace zypp
* const char * data[] = {
* "@ product"
* ,"@ installed"
- * ,"prodold 1 1 x86_64"
+ * ,"- prodold 1 1 x86_64"
* ,"@ available"
- * ,"prodnew 1 1 x86_64"
+ * ,"- prodnew 1 1 x86_64"
* ,"@ obsoletes"
* ,"prodold"
* ,"@ fin"
, _defdep( Dep::PROVIDES )
, _defdepref( _defkind )
, _verbose( verbose_r )
- {}
+ {
+ VendorAttr::disableAutoProtect();
+ }
- void operator()( const std::string & line_r )
- { parseLine( line_r ); }
+ bool operator()( const std::string & line_r )
+ {
+ parseLine( str::trim( line_r ) );
+ return true;
+ }
const ResStore & installed() const
{ return _installed; }
private:
void parseLine( const std::string & line_r )
{
- std::vector<std::string> words;
+ if ( line_r.empty() || line_r[0] == '#' )
+ return;
+
+ std::vector<std::string> words;
str::split( line_r, std::back_inserter( words ) );
if ( words.empty() )
return;
};
///////////////////////////////////////////////////////////////////
- /** \refers DataCollect Stream output. */
+ /** \relates DataCollect Stream output. */
inline std::ostream & operator<<( std::ostream & str, const DataCollect & obj )
{
dumpRange( str << "Installed" << endl,
///////////////////////////////////////////////////////////////////
+ template<class _Iterator>
+ inline void addPool( _Iterator begin_r, _Iterator end_r )
+ {
+ DataCollect dataCollect;
+ dataCollect.collect( begin_r, end_r );
+ getZYpp()->addResolvables( dataCollect.installed(), true );
+ getZYpp()->addResolvables( dataCollect.available() );
+ }
+
+ inline void addPool( const Pathname & file_r )
+ {
+ std::ifstream in( file_r.c_str() );
+ DataCollect dataCollect;
+ function<bool(const std::string &)> fnc( ref(dataCollect) );
+ iostr::forEachLine( in, fnc );
+ getZYpp()->addResolvables( dataCollect.installed(), true );
+ getZYpp()->addResolvables( dataCollect.available() );
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace debug
///////////////////////////////////////////////////////////////////
#include <zypp/base/Function.h>
#include <zypp/base/Iterator.h>
-#include "zypp/ZYppFactory.h"
-#include "zypp/ResPoolProxy.h"
#include <zypp/SourceManager.h>
#include <zypp/SourceFactory.h>
-
#include "zypp/ZYppCallbacks.h"
+
#include "zypp/NVRAD.h"
-#include "zypp/ResPool.h"
#include "zypp/ResFilters.h"
#include "zypp/CapFilters.h"
-#include "zypp/Package.h"
-#include "zypp/Pattern.h"
-#include "zypp/Language.h"
#include "zypp/PackageKeyword.h"
-#include "zypp/NameKindProxy.h"
#include "zypp/pool/GetResolvablesToInsDel.h"
using namespace std;
///////////////////////////////////////////////////////////////////
-template<class _Iterator>
- void addPool( _Iterator begin_r, _Iterator end_r )
+struct SetTransactValue
+{
+ SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
+ : _newVal( newVal_r )
+ , _causer( causer_r )
+ {}
+
+ ResStatus::TransactValue _newVal;
+ ResStatus::TransactByValue _causer;
+
+ bool operator()( const PoolItem & pi ) const
+ {
+ bool ret = pi.status().setTransactValue( _newVal, _causer );
+ if ( ! ret )
+ ERR << _newVal << _causer << " " << pi << endl;
+ return ret;
+ }
+};
+
+struct StatusReset : public SetTransactValue
+{
+ StatusReset()
+ : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
+ {}
+};
+
+struct StatusInstall : public SetTransactValue
+{
+ StatusInstall()
+ : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
+ {}
+};
+
+inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
+{
+ if ( nkp.availableEmpty() )
+ {
+ ERR << "No Item to select: " << nkp << endl;
+ return false;
+ ZYPP_THROW( Exception("No Item to select") );
+ }
+
+ if ( arch != Arch() )
+ {
+ typeof( nkp.availableBegin() ) it = nkp.availableBegin();
+ for ( ; it != nkp.availableEnd(); ++it )
+ {
+ if ( (*it)->arch() == arch )
+ return (*it).status().setTransact( true, ResStatus::USER );
+ }
+ }
+
+ return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
+}
+
+///////////////////////////////////////////////////////////////////
+
+bool solve( bool establish = false )
{
- using zypp::debug::DataCollect;
- DataCollect dataCollect;
- dataCollect.collect( begin_r, end_r );
- getZYpp()->addResolvables( dataCollect.installed(), true );
- getZYpp()->addResolvables( dataCollect.available() );
- vdumpPoolStats( USR << "Pool:" << endl,
- getZYpp()->pool().begin(),
- getZYpp()->pool().end() ) << endl;
+ if ( establish )
+ {
+ bool eres = getZYpp()->resolver()->establishPool();
+ if ( ! eres )
+ {
+ ERR << "establish " << eres << endl;
+ return false;
+ }
+ MIL << "establish " << eres << endl;
+ }
+
+ bool rres = getZYpp()->resolver()->resolvePool();
+ if ( ! rres )
+ {
+ ERR << "resolve " << rres << endl;
+ return false;
+ }
+ MIL << "resolve " << rres << endl;
+ return true;
}
+///////////////////////////////////////////////////////////////////
+
/******************************************************************
**
** FUNCTION NAME : main
int main( int argc, char * argv[] )
{
INT << "===[START]==========================================" << endl;
+ ///////////////////////////////////////////////////////////////////
+ // define pool
+ ///////////////////////////////////////////////////////////////////
+ if ( 0 )
+ {
+ const char * data[] = {
+ "@ product",
+ "@ installed",
+ "- prodold 1 1 x86_64",
+ "@ available",
+ "- prodnew 1 1 x86_64",
+ "@ obsoletes",
+ "prodold",
+ "@ fin",
+ };
+ debug::addPool( data, data + ( sizeof(data) / sizeof(const char *) ) );
+ }
+ else
+ {
+ debug::addPool( "SRC/iorderbug.pool" );
+ }
+ ResPool pool( getZYpp()->pool() );
+ vdumpPoolStats( USR << "Initial pool:" << endl,
+ pool.begin(),
+ pool.end() ) << endl;
- const char * data[] = {
- "@ package",
- "@ installed",
- "@ available",
- "- glibc 2.3.4 31 i686",
- "- glibc 2.3.5 28 i586",
- "- glibc-locale 2.3.5 28 i686",
- "@ requires",
- "glibc == 2.3.5",
- "@ fin"
- };
- addPool( data, data + ( sizeof(data) / sizeof(const char *) ) );
+ ///////////////////////////////////////////////////////////////////
+ // define transaction
+ ///////////////////////////////////////////////////////////////////
+ if ( 0 )
+ for_each( pool.byKindBegin<Product>(), pool.byKindEnd<Product>(), StatusInstall() );
- ResPool pool( getZYpp()->pool() );
+#define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
+ selt( Package, bash );
+ selt( Package, readline );
+ selt( Package, fontcfg );
+#undef selt
+
+ ///////////////////////////////////////////////////////////////////
+ // solve
+ ///////////////////////////////////////////////////////////////////
+ if ( 0 )
+ {
+ solve();
+ }
+
+ vdumpPoolStats( USR << "Transacting:"<< endl,
+ make_filter_begin<resfilter::ByTransact>(pool),
+ make_filter_end<resfilter::ByTransact>(pool) ) << endl;
- vdumpPoolStats( USR << "Pool:" << endl,
- getZYpp()->pool().begin(),
- getZYpp()->pool().end() ) << endl;
+ ///////////////////////////////////////////////////////////////////
+ // install order
+ ///////////////////////////////////////////////////////////////////
+ pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
+ MIL << "GetResolvablesToInsDel:" << endl << collect << endl;
- // solve();
+ if ( 1 )
+ {
+ // Collect until the 1st package from an unwanted media occurs.
+ // Further collection could violate install order.
+ bool hitUnwantedMedia = false;
+ typedef pool::GetResolvablesToInsDel::PoolItemList PoolItemList;
+ PoolItemList::iterator fst=collect._toInstall.end();
+ for ( PoolItemList::iterator it = collect._toInstall.begin(); it != collect._toInstall.end(); ++it)
+ {
+ ResObject::constPtr res( it->resolvable() );
- vdumpPoolStats( USR << "Pool:" << endl,
- getZYpp()->pool().begin(),
- getZYpp()->pool().end() ) << endl;
+ if ( hitUnwantedMedia
+ || ( res->sourceMediaNr() && res->sourceMediaNr() != 1 ) )
+ {
+ if ( !hitUnwantedMedia )
+ fst=it;
+ hitUnwantedMedia = true;
+ }
+ else
+ {
+ }
+ }
+ dumpRange( WAR << "toInstall1: " << endl,
+ collect._toInstall.begin(), fst ) << endl;
+ dumpRange( WAR << "toInstall2: " << endl,
+ fst, collect._toInstall.end() ) << endl;
+ dumpRange( ERR << "toDelete: " << endl,
+ collect._toDelete.begin(), collect._toDelete.end() ) << endl;
+ }
+ else
+ {
+ dumpRange( WAR << "toInstall: " << endl,
+ collect._toInstall.begin(), collect._toInstall.end() ) << endl;
+ dumpRange( ERR << "toDelete: " << endl,
+ collect._toDelete.begin(), collect._toDelete.end() ) << endl;
+ }
INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
return 0;
}
MIL << "Metadata saved in " << cache_dir_r << ". Setting as cache." << std::endl;
_cache_dir = cache_dir_r;
-
+
readRepomd();
}
_repo_pattern.clear();
_repo_product.clear();
_repo_patches.clear();
-
+
parser::ParserProgress::Ptr progress;
callback::SendReport<SourceReport> report;
YUMSourceEventHandler npp(report);
YUMSourceImpl::resolvableKinds() const
{
std::set<zypp::Resolvable::Kind> kinds;
-
+
if (_repo_product.size() > 0 )
- kinds.insert( ResTraits<zypp::Product>::kind );
-
+ kinds.insert( ResTraits<zypp::Product>::kind );
+
if (_repo_pattern.size() > 0 )
kinds.insert( ResTraits<zypp::Pattern>::kind );
-
+
if (_repo_group.size() > 0 )
kinds.insert( ResTraits<zypp::Selection>::kind );
-
+
if (_repo_primary.size() > 0 )
kinds.insert( ResTraits<zypp::Package>::kind );
-
+
if (_repo_patches.size() > 0 )
kinds.insert( ResTraits<zypp::Patch>::kind );
-
+
return kinds;
}
// TranslatorExplanation %s = product file
report->start( selfSourceRef(), str::form(_("Reading product from %s"), filename.asString().c_str()) );
-
+
YUMProductParser product(st, "", progress);
for (; !product.atEnd(); ++product)
{
Arch arch;
if (!parsed.arch.empty())
arch = Arch(parsed.arch);
-
+
string name(parsed.name);
std::replace(name.begin(), name.end(), ' ', '_');
-
+
NVRAD dataCollect( name,
Edition( parsed.ver, parsed.rel, parsed.epoch ),
arch,