From: Jan Kupec Date: Mon, 7 Apr 2008 14:21:22 +0000 (+0000) Subject: - by-status filter re-enabled X-Git-Tag: 6.6.0~1153 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ea8fe59f530147058a36814e6a23b47340c2035;p=platform%2Fupstream%2Flibzypp.git - by-status filter re-enabled - test case added --- diff --git a/tests/zypp/PoolQuery_test.cc b/tests/zypp/PoolQuery_test.cc index 604ea0250..4d93b27e2 100644 --- a/tests/zypp/PoolQuery_test.cc +++ b/tests/zypp/PoolQuery_test.cc @@ -21,6 +21,7 @@ bool result_cb( const sat::Solvable & solvable ) { zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) ); cout << pi.resolvable() << endl; + // name: yast2-sound 2.16.2-9 i586 return true; } @@ -38,7 +39,8 @@ static void init_pool() sat::Pool::instance().addRepoSolv(dir / "factory-nonoss.solv", i2); RepoInfo i3; i3.setAlias("zypp_svn"); sat::Pool::instance().addRepoSolv(dir / "zypp_svn.solv", i3); - sat::Pool::instance().addRepoSolv(dir / "@System.solv"); + RepoInfo i4; i4.setAlias("@System"); + sat::Pool::instance().addRepoSolv(dir / "@System.solv", i4); } BOOST_AUTO_TEST_CASE(pool_query_init) @@ -53,7 +55,10 @@ BOOST_AUTO_TEST_CASE(pool_query_1) cout << "****1****" << endl; PoolQuery q; cout << q.size() << endl; - BOOST_CHECK(q.size() == 11449); + BOOST_CHECK(q.size() == 11451); + //!\todo should be 11453 probably according to: + // dumpsolv factory.solv factory-nonoss.solv zypp_svn.solv \@System.solv | \ + // grep '^name:.*\(noarch\|i386\|i586\|i686\|src\)$' | wc -l } // default query + one search string @@ -162,8 +167,29 @@ BOOST_AUTO_TEST_CASE(pool_query_7) BOOST_CHECK(q1.empty()); } +// match by installed status (basically by system vs. repo) BOOST_AUTO_TEST_CASE(pool_query_8) { + cout << "****8****" << endl; + PoolQuery q; + q.addString("zypper"); + q.addAttribute(sat::SolvAttr::name); + q.setMatchExact(); + q.setInstalledOnly(); + + std::for_each(q.begin(), q.end(), &result_cb); + BOOST_CHECK(q.size() == 1); + + cout << endl; + + PoolQuery q1; + q1.addString("zypper"); + q1.addAttribute(sat::SolvAttr::name); + q1.setMatchExact(); + q1.setUninstalledOnly(); + + std::for_each(q1.begin(), q1.end(), &result_cb); + BOOST_CHECK(q1.size() == 5); } BOOST_AUTO_TEST_CASE(pool_query_save_restore) diff --git a/zypp/PoolQuery.cc b/zypp/PoolQuery.cc index 97b999035..74425c9bc 100644 --- a/zypp/PoolQuery.cc +++ b/zypp/PoolQuery.cc @@ -447,9 +447,10 @@ attremptycheckend: o << "compiled: " << _compiled << endl; - o << "match flags:" << endl; + o << "string match flags:" << endl; o << "* sat: " << (_flags & SEARCH_STRINGMASK) << endl; o << "* SEARCH_REGEX: " << ((_flags & SEARCH_STRINGMASK) == SEARCH_REGEX ? "yes" : "no") << endl; + o << "status filter flags:" << _status_flags << endl; // raw @@ -533,16 +534,35 @@ attremptycheckend: { _sid = _rdit->solvid; + bool new_solvable = true; bool matches = !_do_matching; bool in_repo; + bool drop_by_kind_status; do { //! \todo FIXME Dataiterator returning resolvables belonging to current repo? - in_repo = _sid >= _rdit->repo->start; + in_repo = _sid >= _rdit->repo->start; - if (_do_matching) + if (in_repo && new_solvable) { - if ( !matches && in_repo /*_sid >= 2 *//*_rdit->repo->start*/) + drop_by_kind_status = false; + + // filter by installed uninstalled + if ( (_pqimpl->_status_flags & INSTALLED_ONLY) && + _rdit->repo->name != _pool.systemRepoName() ) + drop_by_kind_status = true; + + if (!drop_by_kind_status) + if ( (_pqimpl->_status_flags & UNINSTALLED_ONLY) && + _rdit->repo->name == _pool.systemRepoName() ) + drop_by_kind_status = true; + + matches = matches && !drop_by_kind_status; + } + + if (_do_matching && !drop_by_kind_status) + { + if (!matches && in_repo) { SolvAttr attr(_rdit->key->name); @@ -566,7 +586,8 @@ attremptycheckend: if ((_has_next = ::dataiterator_step(_rdit))) { - if (!in_repo /*_sid < 2 *//*_rdit->repo->start*/) + new_solvable = _rdit->solvid != _sid; + if (!in_repo) { INT << "repo start: " << _rdit->repo->start << endl; _sid = _rdit->solvid; @@ -579,7 +600,7 @@ attremptycheckend: return matches && in_repo; } } - while (_rdit->solvid == _sid || !in_repo /*_sid < 2 *//*_rdit->repo->start*/); + while (!new_solvable || !in_repo); return matches; } @@ -645,11 +666,11 @@ attremptycheckend: void PoolQuery::setInstalledOnly() - { _pimpl->_status_flags |= INSTALLED_ONLY; } + { _pimpl->_status_flags = INSTALLED_ONLY; } void PoolQuery::setUninstalledOnly() - { _pimpl->_status_flags |= UNINSTALLED_ONLY; } + { _pimpl->_status_flags = UNINSTALLED_ONLY; } void PoolQuery::setStatusFilterFlags( int flags ) - { _pimpl->_status_flags |= flags; } + { _pimpl->_status_flags = flags; } void PoolQuery::requireAll(const bool require_all) diff --git a/zypp/PoolQuery.h b/zypp/PoolQuery.h index 9148c5dca..d6b9f3ce4 100644 --- a/zypp/PoolQuery.h +++ b/zypp/PoolQuery.h @@ -145,9 +145,9 @@ namespace zypp * Filter by status (installed uninstalled) */ enum StatusFilter { - ALL = 1, - INSTALLED_ONLY = 2, - UNINSTALLED_ONLY = 4 + ALL = 0, // both install filter and uninstall filter bits are 0 + INSTALLED_ONLY = 1, + UNINSTALLED_ONLY = 2 }; void setInstalledOnly(); void setUninstalledOnly();