BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14);
}
+/////////////////////////////////////////////////////////////////////////////
+// 6xx queries with edition
+/////////////////////////////////////////////////////////////////////////////
+
+BOOST_AUTO_TEST_CASE(pool_query_X)
+{
+ cout << "****600.1****" << endl;
+ PoolQuery q;
+ q.addAttribute(sat::SolvAttr::name, "zypper");
+ q.setMatchExact();
+ q.setEdition(Edition("0.10.5"), Rel::GT);
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 4);
+
+ cout << "****600.2****" << endl;
+ q.setEdition(Edition("0.10.5"), Rel::LT);
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 0);
+
+ cout << "****600.3****" << endl;
+ q.setEdition(Edition("0.10.5"), Rel::LE);
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2);
+
+ cout << "****600.4****" << endl;
+ q.setEdition(Edition("0.10.5-5"), Rel::LT);
+
+ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2);
+}
+
/*
BOOST_AUTO_TEST_CASE(pool_query_X)
{
#include "zypp/base/Algorithm.h"
#include "zypp/base/String.h"
#include "zypp/repo/RepoException.h"
+#include "zypp/RelCompare.h"
#include "zypp/sat/Pool.h"
#include "zypp/sat/Solvable.h"
mutable AttrCompiledStrMap _rcattrs;
mutable AttrRegexMap _rattrs;
+ /** Edition condition operand */
+ mutable Edition _edition;
+ /** Operator for edition condition */
+ mutable Rel _op;
+
/** Repos to search. */
StrContainer _repos;
/** Kinds to search */
, _repos(pqimpl->_repos)
, _kinds(pqimpl->_kinds)
, _status_flags(pqimpl->_status_flags)
+ , _edition(pqimpl->_edition)
+ , _op(pqimpl->_op)
{
this->base_reference() = LookupAttr::iterator(dip_r, true); //!\todo pass chain_repos
_has_next = (*base_reference() != sat::detail::noId);
, _repos(rhs._repos)
, _kinds(rhs._kinds)
, _status_flags(rhs._status_flags)
+ , _edition(rhs._edition)
+ , _op(rhs._op)
{ base_reference() = LookupAttr::iterator(rhs.base()); }
_repos = rhs._repos;
_kinds = rhs._kinds;
_status_flags = rhs._status_flags;
+ _edition = rhs._edition;
+ _op = rhs._op;
return *this;
}
bool new_solvable = true;
bool matches = !_do_matching;
- bool drop_by_kind_status = false;
+ bool drop_by_kind_status_edition = false;
bool drop_by_repo = false;
do
{
{
while(1)
{
+ // whether to drop a resolvable not belonging to this repo
drop_by_repo = false;
if(!_repos.empty() &&
_repos.find(base().get()->repo->name) == _repos.end())
break;
}
- drop_by_kind_status = false;
+ drop_by_kind_status_edition = false;
+
+ // whether to drop a resolvable not matching the edition condition
+ if (_op != Rel::ANY)
+ {
+ sat::Solvable s(_sid);
+ if (!compareByRel<Edition>( _op, s.edition(), _edition, Edition::Match()))
+ {
+ drop_by_kind_status_edition = true;
+ break;
+ }
+ }
// whether to drop an uninstalled (repo) solvable
if ( (_status_flags & PoolQuery::INSTALLED_ONLY) &&
base().get()->repo->name != sat::Pool::instance().systemRepoName() )
{
- drop_by_kind_status = true;
+ drop_by_kind_status_edition = true;
break;
}
if ((_status_flags & PoolQuery::UNINSTALLED_ONLY) &&
base().get()->repo->name == sat::Pool::instance().systemRepoName())
{
- drop_by_kind_status = true;
+ drop_by_kind_status_edition = true;
break;
}
if (!_kinds.empty())
{
sat::Solvable s(_sid);
- // the user wants to filter by kind.
if (_kinds.find(s.kind()) == _kinds.end())
- drop_by_kind_status = true;
+ drop_by_kind_status_edition = true;
}
break;
}
- matches = matches && !drop_by_kind_status && !drop_by_repo;
+ matches = matches && !drop_by_kind_status_edition && !drop_by_repo;
}
- if (_do_matching && !drop_by_kind_status)
+ if (_do_matching && !drop_by_kind_status_edition)
{
if (!matches)
{
base_reference().nextSkipRepo();
drop_by_repo = false;
}
- else if (drop_by_kind_status)
+ else if (drop_by_kind_status_edition)
{
base_reference().nextSkipSolvable();
- drop_by_kind_status = false;
+ drop_by_kind_status_edition = false;
}
// copy the iterator to forward check for the next attribute ***
{ _pimpl->_attrs[attr].insert(value); }
+ void PoolQuery::setEdition(const Edition & edition, const Rel & op)
+ {
+ _pimpl->_edition = edition;
+ _pimpl->_op = op;
+ }
+
+
void PoolQuery::setCaseSensitive(const bool value)
{
if (value)
return it != _pimpl->_attrs.end() ? it->second : nocontainer;
}
+ const Edition PoolQuery::edition() const
+ { return _pimpl->_edition; }
+ const Rel PoolQuery::editionRel() const
+ { return _pimpl->_op; }
+
+
const PoolQuery::Kinds &
PoolQuery::kinds() const
{ return _pimpl->_kinds; }
*/
struct PoolQueryAttr : public IdStringType<PoolQueryAttr>
{
- private:
- friend class IdStringType<PoolQueryAttr>;
- IdString _str;
- public:
+ private:
+ friend class IdStringType<PoolQueryAttr>;
+ IdString _str;
+ public:
//noAttr
PoolQueryAttr(){}
: _str( str_r )
{}
- //unknown atributes
+ // unknown atributes
static const PoolQueryAttr noAttr;
- // own attributes
+ // PoolQuery's own attributes
static const PoolQueryAttr repoAttr;
static const PoolQueryAttr kindAttr;
static const PoolQueryAttr stringAttr;
static const PoolQueryAttr requireAllAttr;
static const PoolQueryAttr caseSensitiveAttr;
static const PoolQueryAttr installStatusAttr;
+ static const PoolQueryAttr editionAttr;
};
const PoolQueryAttr PoolQueryAttr::noAttr;
const PoolQueryAttr PoolQueryAttr::requireAllAttr("require_all");
const PoolQueryAttr PoolQueryAttr::caseSensitiveAttr("case_sensitive");
const PoolQueryAttr PoolQueryAttr::installStatusAttr("install_status");
+ const PoolQueryAttr PoolQueryAttr::editionAttr("version");
class StringTypeAttr : public IdStringType<PoolQueryAttr>
{
static const StringTypeAttr globAttr;
static const StringTypeAttr wordAttr;
};
- const StringTypeAttr StringTypeAttr::noAttr;
- const StringTypeAttr StringTypeAttr::exactAttr("exact");
- const StringTypeAttr StringTypeAttr::substringAttr("substring");
- const StringTypeAttr StringTypeAttr::regexAttr("regex");
- const StringTypeAttr StringTypeAttr::globAttr("glob");
- const StringTypeAttr StringTypeAttr::wordAttr("word");
+ const StringTypeAttr StringTypeAttr::noAttr;
+
+ const StringTypeAttr StringTypeAttr::exactAttr("exact");
+ const StringTypeAttr StringTypeAttr::substringAttr("substring");
+ const StringTypeAttr StringTypeAttr::regexAttr("regex");
+ const StringTypeAttr StringTypeAttr::globAttr("glob");
+ const StringTypeAttr StringTypeAttr::wordAttr("word");
///////////////////////////////////////////////////////////////////
WAR << "Unknown value for install status " << attrValue << endl;
}
}
+ else if ( attribute == PoolQueryAttr::editionAttr)
+ {
+ string::size_type pos;
+ Rel rel;
+ if (attrValue.find_first_of("=<>") == 0)
+ {
+ pos = attrValue.find_last_of("=<>");
+ rel = Rel(attrValue.substr(0, pos+1));
+ attrValue = attrValue.substr(pos+1, attrValue.npos);
+ }
+
+ setEdition(Edition(attrValue), rel);
+ }
else if ( attribute==PoolQueryAttr::noAttr )
{
WAR << "empty attribute name" << endl;
<< it->idStr() << delim ;
}
+ if (editionRel() != Rel::ANY && edition() != Edition::noedition)
+ str << PoolQueryAttr::editionAttr.asString() << ": " << editionRel() << " " << edition() << delim;
+
if (matchType()!=q.matchType())
{
switch( matchType() )
#include "zypp/base/PtrTypes.h"
#include "zypp/base/Function.h"
+#include "zypp/Edition.h"
extern "C"
{
void addAttribute(const sat::SolvAttr & attr, const std::string & value = "");
/**
- * Filter by Selectable status.
- *
- * This should cover also plain 'is installed' and 'not installed' statuses.
- *
- * \param status Selectable status (zypp::ui::Status enum)
+ * Set version condition. This will filter out solvables not matching
+ * <tt>solvableEdition \a op \a edition</tt>.
+ *
+ * \param edition Edition to look for.
+ * \param op Found-wanted relation operator.
*/
- //void addStatus(const Status status);
+ void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
/**
* Add dependency filter.
/**
- * Require that all of the values set by addString, addAttribute, addDep
- * match the values of respective attributes.
+ * Require that all of the values set by addString or addAttribute
+ * match the values of respective attributes.
+ *
+ * \todo doesn't work yet, don't use this function
*/
void setRequireAll(const bool require_all = true);
+
/** \name getters */
//@{
const StrContainer & repos() const;
+ const Edition edition() const;
+ const Rel editionRel() const;
+
/**
* returns true if search is case sensitive
*/
bool matchSubstring() const;
bool matchGlob() const;
bool matchRegex() const;
+ bool matchWord() const;
+
/**
* Returns currently used string matching type.
* \see satsolver/repo.h
*/
int matchType() const;
- bool matchWord() const;
-
+ /**
+ * Whether all values added via addString() or addAttribute() are required
+ * to match the values of the respective attributes.
+ */
bool requireAll() const;
StatusFilter statusFilterFlags() const;
PoolQuery::Kinds _kinds;
/** Installed status filter flags. \see PoolQuery::StatusFilter */
int _status_flags;
+
+ Edition _edition;
+ Rel _op;
//@}
/** used to copy current iterator in order to forward check for next attributes */