libzypp  13.10.6
PoolQuery.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <sstream>
14 
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/LogTools.h"
17 #include "zypp/base/Algorithm.h"
18 #include "zypp/base/String.h"
20 #include "zypp/RelCompare.h"
21 
22 #include "zypp/sat/Pool.h"
23 #include "zypp/sat/Solvable.h"
24 #include "zypp/base/StrMatcher.h"
25 
26 #include "zypp/PoolQuery.h"
27 
28 #undef ZYPP_BASE_LOGGER_LOGGROUP
29 #define ZYPP_BASE_LOGGER_LOGGROUP "PoolQuery"
30 
31 using namespace std;
32 using namespace zypp::sat;
33 
35 namespace zypp
36 {
37 
39  namespace
40  {
41 
43  // some Helpers and Predicates
45 
46  bool isDependencyAttribute( sat::SolvAttr attr_r )
47  {
48  static sat::SolvAttr deps[] = {
49  SolvAttr::provides,
50  SolvAttr::requires,
51  SolvAttr::recommends,
52  SolvAttr::obsoletes,
53  SolvAttr::conflicts,
54  SolvAttr::suggests,
55  SolvAttr::supplements,
56  SolvAttr::enhances,
57  };
58  for_( it, arrayBegin(deps), arrayEnd(deps) )
59  if ( *it == attr_r )
60  return true;
61  return false;
62  }
63 
68  struct EditionRangePredicate
69  {
70  EditionRangePredicate( const Rel & op, const Edition & edition )
71  : _range( op, edition )
72  , _arch( Arch_empty )
73  {}
74  EditionRangePredicate( const Rel & op, const Edition & edition, const Arch & arch )
75  : _range( op, edition )
76  , _arch( arch )
77  {}
78 
79  bool operator()( sat::LookupAttr::iterator iter_r )
80  {
81  if ( !_arch.empty() && iter_r.inSolvable().arch() != _arch )
82  return false;
83 
84  CapDetail cap( iter_r.id() );
85  if ( ! cap.isSimple() )
86  return false;
87  if ( cap.isNamed() ) // no range to match
88  return true;
89  return overlaps( Edition::MatchRange( cap.op(), cap.ed() ), _range );
90  }
91 
92  std::string serialize() const
93  {
94  std::string ret( "EditionRange" );
95  str::appendEscaped( ret, _range.op.asString() );
96  str::appendEscaped( ret, _range.value.asString() );
97  str::appendEscaped( ret, _arch.asString() );
98  return ret;
99  }
100 
101  Edition::MatchRange _range;
102  Arch _arch;
103  };
104 
106  struct SolvableRangePredicate
107  {
108  SolvableRangePredicate( const Rel & op, const Edition & edition )
109  : _range( op, edition )
110  , _arch( Arch_empty )
111  {}
112 
113  SolvableRangePredicate( const Rel & op, const Edition & edition, const Arch & arch )
114  : _range( op, edition )
115  , _arch( arch )
116  {}
117 
118  bool operator()( sat::LookupAttr::iterator iter_r )
119  {
120  if ( !_arch.empty() && iter_r.inSolvable().arch() != _arch )
121  return false;
122  return overlaps( Edition::MatchRange( Rel::EQ, iter_r.inSolvable().edition() ), _range );
123  }
124 
125  std::string serialize() const
126  {
127  std::string ret( "SolvableRange" );
128  str::appendEscaped( ret, _range.op.asString() );
129  str::appendEscaped( ret, _range.value.asString() );
130  str::appendEscaped( ret, _arch.asString() );
131  return ret;
132  }
133 
134  Edition::MatchRange _range;
135  Arch _arch;
136  };
137 
142  struct CapabilityMatchPredicate
143  {
144  CapabilityMatchPredicate( Capability cap_r )
145  : _cap( cap_r )
146  {}
147 
148  bool operator()( sat::LookupAttr::iterator iter_r ) const
149  {
150  return _cap.matches( iter_r.asType<Capability>() ) == CapMatch::yes;
151  }
152 
153  std::string serialize() const
154  {
155  std::string ret( "CapabilityMatch" );
156  str::appendEscaped( ret, _cap.asString() );
157  return ret;
158  }
159 
160  Capability _cap;
161  };
162 
164  //
166 
184  struct AttrMatchData
185  {
186  typedef function<bool(sat::LookupAttr::iterator)> Predicate;
187 
188  static bool always( sat::LookupAttr::iterator ) { return true; }
189  static bool never( sat::LookupAttr::iterator ) { return false; }
190 
191  AttrMatchData()
192  {}
193 
194  AttrMatchData( sat::SolvAttr attr_r, const StrMatcher & strMatcher_r )
195  : attr( attr_r )
196  , strMatcher( strMatcher_r )
197  {}
198 
199  AttrMatchData( sat::SolvAttr attr_r, const StrMatcher & strMatcher_r,
200  const Predicate & predicate_r, const std::string & predicateStr_r )
201  : attr( attr_r )
202  , strMatcher( strMatcher_r )
203  , predicate( predicate_r )
204  , predicateStr( predicateStr_r )
205  {}
206 
212  template<class _Predicate>
213  void addPredicate( const _Predicate & predicate_r )
214  {
215  predicate = predicate_r;
216  predicateStr = predicate_r.serialize();
217  }
218 
224  std::string serialize() const
225  {
226  std::string ret( "AttrMatchData" );
227  str::appendEscaped( ret, attr.asString() );
228  str::appendEscaped( ret, strMatcher.searchstring() );
229  // TODO: Actually the flag should be serialized too, but for PoolQuery
230  // it's by now sufficient to differ between mode OTHER and others,
231  // i.e. whether to compile or not compile.
232  str::appendEscaped( ret, strMatcher.flags().mode() == Match::OTHER ? "C" : "X" );
234  return ret;
235  }
236 
240  static AttrMatchData deserialize( const std::string & str_r )
241  {
242  std::vector<std::string> words;
243  str::splitEscaped( str_r, std::back_inserter(words) );
244  if ( words.empty() || words[0] != "AttrMatchData" )
245  ZYPP_THROW( Exception( str::Str() << "Expecting AttrMatchData: " << str_r ) );
246  if ( words.size() != 5 )
247  ZYPP_THROW( Exception( str::Str() << "Wrong number of words: " << str_r ) );
248 
249  AttrMatchData ret;
250  ret.attr = sat::SolvAttr( words[1] );
251  ret.strMatcher = StrMatcher( words[2] );
252  if ( words[3] == "C" )
253  ret.strMatcher.setFlags( Match::OTHER );
254  ret.predicateStr = words[4];
255 
256  // now the predicate
257  words.clear();
258  str::splitEscaped( ret.predicateStr, std::back_inserter(words) );
259  if ( ! words.empty() )
260  {
261  if ( words[0] == "EditionRange" )
262  {
263  switch( words.size() )
264  {
265  case 3:
266  ret.predicate = EditionRangePredicate( Rel(words[1]), Edition(words[2]) );
267  break;
268  case 4:
269  ret.predicate = EditionRangePredicate( Rel(words[1]), Edition(words[2]), Arch(words[3]) );
270  break;
271  default:
272  ZYPP_THROW( Exception( str::Str() << "Wrong number of words: " << str_r ) );
273  break;
274  }
275  }
276  else if ( words[0] == "SolvableRange" )
277  {
278  switch( words.size() )
279  {
280  case 3:
281  ret.predicate = SolvableRangePredicate( Rel(words[1]), Edition(words[2]) );
282  break;
283  case 4:
284  ret.predicate = SolvableRangePredicate( Rel(words[1]), Edition(words[2]), Arch(words[3]) );
285  break;
286  default:
287  ZYPP_THROW( Exception( str::Str() << "Wrong number of words: " << str_r ) );
288  break;
289  }
290  }
291  else if ( words[0] == "CapabilityMatch" )
292  {
293  if ( words.size() != 2 )
294  ZYPP_THROW( Exception( str::Str() << "Wrong number of words: " << str_r ) );
295  ret.predicate = CapabilityMatchPredicate( Capability(words[1]) );
296  }
297  else
298  ZYPP_THROW( Exception( str::Str() << "Unknown predicate: " << str_r ) );
299  }
300  return ret;
301  }
302 
303  sat::SolvAttr attr;
304  StrMatcher strMatcher;
305  Predicate predicate;
306  std::string predicateStr;
307  };
308 
310  inline std::ostream & operator<<( std::ostream & str, const AttrMatchData & obj )
311  {
312  str << obj.attr << ": " << obj.strMatcher;
313  if ( obj.predicate )
314  str << " +(" << obj.predicateStr << ")";
315  return str;
316  }
317 
319  inline bool operator==( const AttrMatchData & lhs, const AttrMatchData & rhs )
320  {
321  return ( lhs.attr == rhs.attr
322  && lhs.strMatcher == rhs.strMatcher
323  && lhs.predicateStr == rhs.predicateStr );
324  }
325 
327  inline bool operator!=( const AttrMatchData & lhs, const AttrMatchData & rhs )
328  { return !( lhs == rhs ); }
329 
331  inline bool operator<( const AttrMatchData & lhs, const AttrMatchData & rhs )
332  {
333  if ( lhs.attr != rhs.attr )
334  return ( lhs.attr < rhs.attr );
335  if ( lhs.strMatcher != rhs.strMatcher )
336  return ( lhs.strMatcher < rhs.strMatcher );
337  if ( lhs.predicateStr != rhs.predicateStr )
338  return ( lhs.predicateStr < rhs.predicateStr );
339  return false;
340  }
341 
342  typedef std::list<AttrMatchData> AttrMatchList;
343 
344 
345  }
346  // namespace
348 
350  //
351  // CLASS NAME : PoolQuery::Impl
352  //
355  {
356  public:
358  : _flags( Match::SUBSTRING | Match::NOCASE | Match::SKIP_KIND )
359  , _match_word(false)
360  , _require_all(false)
361  , _status_flags(ALL)
362  {}
363 
365  {}
366 
367  public:
369  string asString() const;
370 
378  std::set<AttrMatchData> _uncompiledPredicated;
379 
384 
387 
392 
395 
399 
400  public:
401 
402  bool operator==( const PoolQuery::Impl & rhs ) const
403  {
404  if ( _flags == rhs._flags
405  // bnc#792901: while libzypp uses exact match mode for a single
406  // package name lock, zypper always uses glob. :(
407  // We unify those two forms to enable zypper to remove zypp locks
408  // without need to actually evaluate the query (which would require
409  // repos to be loaded).
410  || ( ( _flags.isModeString() && rhs._flags.isModeGlob()
411  || _flags.isModeGlob() && rhs._flags.isModeString() )
412  && _strings.empty()
413  && _attrs.size() == 1
414  && _attrs.begin()->first == sat::SolvAttr::name ) )
415  {
416  return ( _strings == rhs._strings
417  && _attrs == rhs._attrs
418  && _uncompiledPredicated == rhs._uncompiledPredicated
419  && _match_word == rhs._match_word
420  && _require_all == rhs._require_all
421  && _status_flags == rhs._status_flags
422  && _edition == rhs._edition
423  && _op == rhs._op
424  && _repos == rhs._repos
425  && _kinds == rhs._kinds );
426  }
427  return false;
428  }
429 
430  bool operator!=( const PoolQuery::Impl & rhs ) const
431  { return ! operator==( rhs ); }
432 
433  public:
438  void compile() const;
439 
441  mutable AttrMatchList _attrMatchList;
442 
443  private:
445  string createRegex( const StrContainer & container, const Match & flags ) const;
446 
447  private:
448  friend Impl * rwcowClone<Impl>( const Impl * rhs );
450  Impl * clone() const
451  { return new Impl( *this ); }
452  };
453 
455 
456  struct MyInserter
457  {
458  MyInserter(PoolQuery::StrContainer & cont) : _cont(cont) {}
459 
460  bool operator()(const string & str)
461  {
462  _cont.insert(str);
463  return true;
464  }
465 
467  };
468 
469 
470  struct EmptyFilter
471  {
472  bool operator()(const string & str)
473  {
474  return !str.empty();
475  }
476  };
477 
478  void PoolQuery::Impl::compile() const
479  {
480  _attrMatchList.clear();
481 
482  Match cflags( _flags );
483  if ( cflags.mode() == Match::OTHER ) // this will never succeed...
485 
487  string rcstrings;
488 
489 
490  // 'different' - will have to iterate through all and match by ourselves (slow)
491  // 'same' - will pass the compiled string to dataiterator_init
492  // 'one-attr' - will pass it to dataiterator_init
493  // 'one-non-regex-str' - will pass to dataiterator_init, set flag to SEARCH_STRING or SEARCH_SUBSTRING
494 
495  // // NO ATTRIBUTE
496  // else
497  // for all _strings
498  // create regex; store in rcstrings; if more strings flag regex;
499  if (_attrs.empty())
500  {
501  ; // A default 'query-all' will be added after all sources are processed.
502  }
503 
504  // // ONE ATTRIBUTE
505  // else if _attrs is not empty but it contains just one attr
506  // for all _strings and _attr[key] strings
507  // create regex; flag 'one-attr'; if more strings flag regex;
508  else if (_attrs.size() == 1)
509  {
510  StrContainer joined;
511  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
512  invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
513  rcstrings = createRegex(joined, cflags);
514  if (joined.size() > 1) // switch to regex for multiple strings
515  cflags.setModeRegex();
516  _attrMatchList.push_back( AttrMatchData( _attrs.begin()->first,
517  StrMatcher( rcstrings, cflags ) ) );
518  }
519 
520  // // MULTIPLE ATTRIBUTES
521  else
522  {
523  // check whether there are any per-attribute strings
524  bool attrvals_empty = true;
525  for (AttrRawStrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
526  if (!ai->second.empty())
527  for(StrContainer::const_iterator it = ai->second.begin();
528  it != ai->second.end(); it++)
529  if (!it->empty())
530  {
531  attrvals_empty = false;
532  goto attremptycheckend;
533  }
534 attremptycheckend:
535 
536  // chceck whether the per-attribute strings are all the same
537  bool attrvals_thesame = true;
538  AttrRawStrMap::const_iterator ai = _attrs.begin();
539  const StrContainer & set1 = ai->second;
540  ++ai;
541  for (; ai != _attrs.end(); ++ai)
542  {
543  StrContainer result;
544  set_difference(
545  set1.begin(), set1.end(),
546  ai->second.begin(), ai->second.end(),
547  inserter(result, result.begin())/*, ltstr()*/);
548  if (!result.empty())
549  {
550  attrvals_thesame = false;
551  break;
552  }
553  }
554 
555  // // THE SAME STRINGS FOR DIFFERENT ATTRS
556  // else if _attrs is not empty but it does not contain strings
557  // for each key in _attrs take all _strings
558  // create regex; store in rcstrings; flag 'same'; if more strings flag regex;
559  if (attrvals_empty || attrvals_thesame)
560  {
561  StrContainer joined;
562  if (attrvals_empty)
563  {
564  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
565  rcstrings = createRegex(joined, cflags);
566  }
567  else
568  {
569  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
570  invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
571  rcstrings = createRegex(joined, cflags);
572  }
573  if (joined.size() > 1) // switch to regex for multiple strings
574  cflags.setModeRegex();
575  // May use the same StrMatcher for all
576  StrMatcher matcher( rcstrings, cflags );
577  for_( ai, _attrs.begin(), _attrs.end() )
578  {
579  _attrMatchList.push_back( AttrMatchData( ai->first, matcher ) );
580  }
581  }
582 
583  // // DIFFERENT STRINGS FOR DIFFERENT ATTRS
584  // if _attrs is not empty and it contains non-empty vectors with non-empty strings
585  // for each key in _attrs take all _strings + all _attrs[key] strings
586  // create regex; flag 'different'; if more strings flag regex;
587  else
588  {
589  for_(ai, _attrs.begin(), _attrs.end())
590  {
591  StrContainer joined;
592  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
593  invokeOnEach(ai->second.begin(), ai->second.end(), EmptyFilter(), MyInserter(joined));
594  string s = createRegex(joined, cflags);
595  if (joined.size() > 1) // switch to regex for multiple strings
596  cflags.setModeRegex();
597  _attrMatchList.push_back( AttrMatchData( ai->first,
598  StrMatcher( s, cflags ) ) );
599  }
600  }
601  }
602 
603  // Now handle any predicated queries
604  if ( ! _uncompiledPredicated.empty() )
605  {
606  StrContainer global;
607  invokeOnEach( _strings.begin(), _strings.end(), EmptyFilter(), MyInserter(global) );
608  for_( it, _uncompiledPredicated.begin(), _uncompiledPredicated.end() )
609  {
610  if ( it->strMatcher.flags().mode() == Match::OTHER )
611  {
612  // need to compile:
613  StrContainer joined( global );
614  const std::string & mstr( it->strMatcher.searchstring() );
615  if ( ! mstr.empty() )
616  joined.insert( mstr );
617 
618  cflags = _flags;
619  rcstrings = createRegex( joined, cflags );
620  if ( joined.size() > 1 ) // switch to regex for multiple strings
621  cflags.setModeRegex();
622 
623  _attrMatchList.push_back( AttrMatchData( it->attr,
624  StrMatcher( rcstrings, cflags ),
625  it->predicate, it->predicateStr ) );
626  }
627  else
628  {
629  // copy matcher
630  _attrMatchList.push_back( *it );
631  }
632  }
633  }
634 
635  // If no attributes defined at all, then add 'query all'
636  if ( _attrMatchList.empty() )
637  {
638  cflags = _flags;
639  rcstrings = createRegex( _strings, cflags );
640  if ( _strings.size() > 1 ) // switch to regex for multiple strings
641  cflags.setModeRegex();
642  _attrMatchList.push_back( AttrMatchData( sat::SolvAttr::allAttr,
643  StrMatcher( rcstrings, cflags ) ) );
644  }
645 
646  // Finally check here, whether all involved regex compile.
647  for_( it, _attrMatchList.begin(), _attrMatchList.end() )
648  {
649  it->strMatcher.compile(); // throws on error
650  }
651  //DBG << asString() << endl;
652  }
653 
654 
658  static string wildcards2regex(const string & str)
659  {
660  string regexed = str;
661 
662  string r_all(".*"); // regex equivalent of '*'
663  string r_one("."); // regex equivalent of '?'
664  string::size_type pos;
665 
666  // replace all "*" in input with ".*"
667  for (pos = 0; (pos = regexed.find("*", pos)) != std::string::npos; pos+=2)
668  regexed = regexed.replace(pos, 1, r_all);
669 
670  // replace all "?" in input with "."
671  for (pos = 0; (pos = regexed.find('?', pos)) != std::string::npos; ++pos)
672  regexed = regexed.replace(pos, 1, r_one);
673 
674  return regexed;
675  }
676 
677  string PoolQuery::Impl::createRegex( const StrContainer & container, const Match & flags ) const
678  {
680 #define WB (_match_word ? string("\\b") : string())
681  string rstr;
682 
683  if (container.empty())
684  return rstr;
685 
686  if (container.size() == 1)
687  {
688  return WB + *container.begin() + WB;
689  }
690 
691  // multiple strings
692 
693  bool use_wildcards = flags.isModeGlob();
694  StrContainer::const_iterator it = container.begin();
695  string tmp;
696 
697  if (use_wildcards)
698  tmp = wildcards2regex(*it);
699  else
700  tmp = *it;
701 
702  if (_require_all)
703  {
704  if ( ! flags.isModeString() ) // not match exact
705  tmp += ".*" + WB + tmp;
706  rstr = "(?=" + tmp + ")";
707  }
708  else
709  {
710  if ( flags.isModeString() || flags.isModeGlob() )
711  rstr = "^";
712  rstr += WB + "(" + tmp;
713  }
714 
715  ++it;
716 
717  for (; it != container.end(); ++it)
718  {
719  if (use_wildcards)
720  tmp = wildcards2regex(*it);
721  else
722  tmp = *it;
723 
724  if (_require_all)
725  {
726  if ( ! flags.isModeString() ) // not match exact
727  tmp += ".*" + WB + tmp;
728  rstr += "(?=" + tmp + ")";
729  }
730  else
731  {
732  rstr += "|" + tmp;
733  }
734  }
735 
736  if (_require_all)
737  {
738  if ( ! flags.isModeString() ) // not match exact
739  rstr += WB + ".*";
740  }
741  else
742  {
743  rstr += ")" + WB;
744  if ( flags.isModeString() || flags.isModeGlob() )
745  rstr += "$";
746  }
747 
748  return rstr;
749 #undef WB
750  }
751 
753  {
754  ostringstream o;
755 
756  o << "kinds: ";
757  if ( _kinds.empty() )
758  o << "ALL";
759  else
760  {
761  for(Kinds::const_iterator it = _kinds.begin();
762  it != _kinds.end(); ++it)
763  o << *it << " ";
764  }
765  o << endl;
766 
767  o << "repos: ";
768  if ( _repos.empty() )
769  o << "ALL";
770  else
771  {
772  for(StrContainer::const_iterator it = _repos.begin();
773  it != _repos.end(); ++it)
774  o << *it << " ";
775  }
776  o << endl;
777 
778  o << "version: "<< _op << " " << _edition.asString() << endl;
779  o << "status: " << ( _status_flags ? ( _status_flags == INSTALLED_ONLY ? "INSTALLED_ONLY" : "UNINSTALLED_ONLY" )
780  : "ALL" ) << endl;
781 
782  o << "string match flags: " << Match(_flags) << endl;
783 
784  // raw
785  o << "strings: ";
786  for(StrContainer::const_iterator it = _strings.begin();
787  it != _strings.end(); ++it)
788  o << *it << " ";
789  o << endl;
790 
791  o << "attributes: " << endl;
792  for(AttrRawStrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
793  {
794  o << "* " << ai->first << ": ";
795  for(StrContainer::const_iterator vi = ai->second.begin();
796  vi != ai->second.end(); ++vi)
797  o << *vi << " ";
798  o << endl;
799  }
800 
801  o << "predicated: " << endl;
802  for_( it, _uncompiledPredicated.begin(), _uncompiledPredicated.end() )
803  {
804  o << "* " << *it << endl;
805  }
806 
807  // compiled
808  o << "last attribute matcher compiled: " << endl;
809  if ( _attrMatchList.empty() )
810  {
811  o << "not yet compiled" << endl;
812  }
813  else
814  {
815  for_( it, _attrMatchList.begin(), _attrMatchList.end() )
816  {
817  o << "* " << *it << endl;
818  }
819  }
820  return o.str();
821  }
822 
824 
826  //
827  // CLASS NAME : PoolQuery
828  //
830 
831  PoolQuery::PoolQuery()
832  : _pimpl(new Impl())
833  {}
834 
836  {}
837 
838  void PoolQuery::addRepo(const std::string &repoalias)
839  {
840  if (repoalias.empty())
841  {
842  WAR << "ignoring an empty repository alias" << endl;
843  return;
844  }
845  _pimpl->_repos.insert(repoalias);
846  }
847 
848  void PoolQuery::addKind(const ResKind & kind)
849  { _pimpl->_kinds.insert(kind); }
850 
851  void PoolQuery::addString(const string & value)
852  { _pimpl->_strings.insert(value); }
853 
854  void PoolQuery::addAttribute(const sat::SolvAttr & attr, const std::string & value)
855  { _pimpl->_attrs[attr].insert(value); }
856 
857  void PoolQuery::addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition )
858  { return addDependency( attr, name, op, edition, Arch_empty ); }
859 
860  void PoolQuery::addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch )
861  {
862  switch ( op.inSwitch() )
863  {
864  case Rel::ANY_e: // no additional constraint on edition.
865  if ( arch.empty() ) // no additional constraint on arch.
866  {
867  addAttribute( attr, name );
868  return;
869  }
870  break;
871 
872  case Rel::NONE_e: // will never match.
873  return;
874 
875  default: // go and add the predicated query (uncompiled)
876  break;
877  }
878 
879  // Match::OTHER indicates need to compile
880  // (merge global search strings into name).
881  AttrMatchData attrMatchData( attr, StrMatcher( name, Match::OTHER ) );
882 
883  if ( isDependencyAttribute( attr ) )
884  attrMatchData.addPredicate( EditionRangePredicate( op, edition, arch ) );
885  else
886  attrMatchData.addPredicate( SolvableRangePredicate( op, edition, arch ) );
887 
888  _pimpl->_uncompiledPredicated.insert( attrMatchData );
889  }
890 
892  {
893  CapDetail cap( cap_r );
894  if ( ! cap.isSimple() ) // will never match.
895  return;
896 
897  // Matches STRING per default. (won't get compiled!)
898  AttrMatchData attrMatchData( attr, StrMatcher( cap.name().asString() ) );
899 
900  if ( isDependencyAttribute( attr ) )
901  attrMatchData.addPredicate( CapabilityMatchPredicate( cap_r ) );
902  else
903  attrMatchData.addPredicate( SolvableRangePredicate( cap.op(), cap.ed() ) );
904 
905  _pimpl->_uncompiledPredicated.insert( attrMatchData );
906  }
907 
908  void PoolQuery::setEdition(const Edition & edition, const Rel & op)
909  {
910  _pimpl->_edition = edition;
911  _pimpl->_op = op;
912  }
913 
914  void PoolQuery::setMatchSubstring() { _pimpl->_flags.setModeSubstring(); }
915  void PoolQuery::setMatchExact() { _pimpl->_flags.setModeString(); }
916  void PoolQuery::setMatchRegex() { _pimpl->_flags.setModeRegex(); }
917  void PoolQuery::setMatchGlob() { _pimpl->_flags.setModeGlob(); }
919  {
920  _pimpl->_match_word = true;
921  _pimpl->_flags.setModeRegex();
922  }
923 
925  { return _pimpl->_flags; }
926  void PoolQuery::setFlags( const Match & flags )
927  { _pimpl->_flags = flags; }
928 
929 
931  { _pimpl->_status_flags = INSTALLED_ONLY; }
933  { _pimpl->_status_flags = UNINSTALLED_ONLY; }
935  { _pimpl->_status_flags = flags; }
936 
937 
938  void PoolQuery::setRequireAll(bool require_all)
939  { _pimpl->_require_all = require_all; }
940 
941 
944  { return _pimpl->_strings; }
945 
948  { return _pimpl->_attrs; }
949 
952  {
953  static const PoolQuery::StrContainer nocontainer;
954  AttrRawStrMap::const_iterator it = _pimpl->_attrs.find(attr);
955  return it != _pimpl->_attrs.end() ? it->second : nocontainer;
956  }
957 
959  { return _pimpl->_edition; }
961  { return _pimpl->_op; }
962 
963 
964  const PoolQuery::Kinds &
966  { return _pimpl->_kinds; }
967 
970  { return _pimpl->_repos; }
971 
972 
974  { return !_pimpl->_flags.test( Match::NOCASE ); }
975  void PoolQuery::setCaseSensitive( bool value )
976  { _pimpl->_flags.turn( Match::NOCASE, !value ); }
977 
979  { return _pimpl->_flags.test( Match::FILES ); }
981  { _pimpl->_flags.turn( Match::FILES, value ); }
982 
983  bool PoolQuery::matchExact() const { return _pimpl->_flags.isModeString(); }
984  bool PoolQuery::matchSubstring() const { return _pimpl->_flags.isModeSubstring(); }
985  bool PoolQuery::matchGlob() const { return _pimpl->_flags.isModeGlob(); }
986  bool PoolQuery::matchRegex() const { return _pimpl->_flags.isModeRegex(); }
987 
988  bool PoolQuery::matchWord() const
989  { return _pimpl->_match_word; }
990 
992  { return _pimpl->_require_all; }
993 
995  { return _pimpl->_status_flags; }
996 
997  bool PoolQuery::empty() const
998  {
999  try { return begin() == end(); }
1000  catch (const Exception & ex) {}
1001  return true;
1002  }
1003 
1005  {
1006  try
1007  {
1008  size_type count = 0;
1009  for_( it, begin(), end() )
1010  ++count;
1011  return count;
1012  }
1013  catch (const Exception & ex) {}
1014  return 0;
1015  }
1016 
1018  { invokeOnEach( begin(), end(), fnc); }
1019 
1020 
1022  //
1023  // CLASS NAME : PoolQuery::Attr
1024  //
1029  struct PoolQueryAttr : public IdStringType<PoolQueryAttr>
1030  {
1031  private:
1034  public:
1035 
1036  //noAttr
1038 
1039  explicit PoolQueryAttr( const char* cstr_r )
1040  : _str( cstr_r )
1041  {}
1042 
1043  explicit PoolQueryAttr( const std::string & str_r )
1044  : _str( str_r )
1045  {}
1046 
1047  // unknown atributes
1048  static const PoolQueryAttr noAttr;
1049 
1050  // PoolQuery's own attributes
1051  static const PoolQueryAttr repoAttr;
1052  static const PoolQueryAttr kindAttr;
1060  };
1061 
1063 
1064  const PoolQueryAttr PoolQueryAttr::repoAttr( "repo" );
1065  const PoolQueryAttr PoolQueryAttr::kindAttr( "type" );
1066  const PoolQueryAttr PoolQueryAttr::stringAttr( "query_string" );
1067  const PoolQueryAttr PoolQueryAttr::stringTypeAttr("match_type");
1068  const PoolQueryAttr PoolQueryAttr::requireAllAttr("require_all");
1069  const PoolQueryAttr PoolQueryAttr::caseSensitiveAttr("case_sensitive");
1070  const PoolQueryAttr PoolQueryAttr::installStatusAttr("install_status");
1071  const PoolQueryAttr PoolQueryAttr::editionAttr("version");
1072  const PoolQueryAttr PoolQueryAttr::complexAttr("complex");
1073 
1074  class StringTypeAttr : public IdStringType<PoolQueryAttr>
1075  {
1078 
1079  public:
1081  explicit StringTypeAttr( const char* cstr_r )
1082  : _str( cstr_r ){}
1083  explicit StringTypeAttr( const std::string & str_r )
1084  : _str( str_r ){}
1085 
1086  static const StringTypeAttr noAttr;
1087 
1091  static const StringTypeAttr globAttr;
1092  static const StringTypeAttr wordAttr;
1093  };
1094 
1096 
1098  const StringTypeAttr StringTypeAttr::substringAttr("substring");
1102 
1104 
1105 
1106  //\TODO maybe ctor with stream can be usefull
1107  //\TODO let it throw, let it throw, let it throw.
1108  bool PoolQuery::recover( istream &str, char delim )
1109  {
1110  bool finded_something = false; //indicates some atributes is finded
1111  string s;
1112  do {
1113  if ( str.eof() )
1114  break;
1115 
1116  getline( str, s, delim );
1117 
1118  if ((!s.empty()) && s[0]=='#') //comment
1119  {
1120  continue;
1121  }
1122 
1123  string::size_type pos = s.find(':');
1124  if (s.empty() || pos == s.npos) // some garbage on line... act like blank line
1125  {
1126  if (finded_something) //is first blank line after record?
1127  {
1128  break;
1129  }
1130  else
1131  {
1132  continue;
1133  }
1134  }
1135 
1136  finded_something = true;
1137 
1138  string attrName(str::trim(string(s,0,pos))); // trimmed name of atribute
1139  string attrValue(str::trim(string(s,pos+1,s.npos))); //trimmed value
1140 
1141  PoolQueryAttr attribute( attrName );
1142 
1143  if ( attribute==PoolQueryAttr::repoAttr )
1144  {
1145  addRepo( attrValue );
1146  }
1147  /* some backwards compatibility */
1148  else if ( attribute==PoolQueryAttr::kindAttr || attribute=="kind" )
1149  {
1150  addKind( ResKind(attrValue) );
1151  }
1152  else if ( attribute==PoolQueryAttr::stringAttr
1153  || attribute=="global_string")
1154  {
1155  addString( attrValue );
1156  }
1157  else if ( attribute==PoolQueryAttr::stringTypeAttr
1158  || attribute=="string_type" )
1159  {
1160  StringTypeAttr s(attrValue);
1161  if( s == StringTypeAttr::regexAttr )
1162  {
1163  setMatchRegex();
1164  }
1165  else if ( s == StringTypeAttr::globAttr )
1166  {
1167  setMatchGlob();
1168  }
1169  else if ( s == StringTypeAttr::exactAttr )
1170  {
1171  setMatchExact();
1172  }
1173  else if ( s == StringTypeAttr::substringAttr )
1174  {
1176  }
1177  else if ( s == StringTypeAttr::wordAttr )
1178  {
1179  setMatchWord();
1180  }
1181  else if ( s == StringTypeAttr::noAttr )
1182  {
1183  WAR << "unknown string type " << attrValue << endl;
1184  }
1185  else
1186  {
1187  WAR << "forget recover some attribute defined as String type attribute: " << attrValue << endl;
1188  }
1189  }
1190  else if ( attribute==PoolQueryAttr::requireAllAttr )
1191  {
1192  if ( str::strToTrue(attrValue) )
1193  {
1194  setRequireAll(true);
1195  }
1196  else if ( !str::strToFalse(attrValue) )
1197  {
1198  setRequireAll(false);
1199  }
1200  else
1201  {
1202  WAR << "unknown boolean value " << attrValue << endl;
1203  }
1204  }
1205  else if ( attribute==PoolQueryAttr::caseSensitiveAttr )
1206  {
1207  if ( str::strToTrue(attrValue) )
1208  {
1209  setCaseSensitive(true);
1210  }
1211  else if ( !str::strToFalse(attrValue) )
1212  {
1213  setCaseSensitive(false);
1214  }
1215  else
1216  {
1217  WAR << "unknown boolean value " << attrValue << endl;
1218  }
1219  }
1220  else if ( attribute==PoolQueryAttr::installStatusAttr )
1221  {
1222  if( attrValue == "all" )
1223  {
1225  }
1226  else if( attrValue == "installed" )
1227  {
1228  setInstalledOnly();
1229  }
1230  else if( attrValue == "not-installed" )
1231  {
1233  }
1234  else
1235  {
1236  WAR << "Unknown value for install status " << attrValue << endl;
1237  }
1238  }
1239  else if ( attribute == PoolQueryAttr::editionAttr)
1240  {
1241  string::size_type pos;
1242  Rel rel("==");
1243  if (attrValue.find_first_of("=<>!") == 0)
1244  {
1245  pos = attrValue.find_last_of("=<>");
1246  rel = Rel(attrValue.substr(0, pos+1));
1247  attrValue = str::trim(attrValue.substr(pos+1, attrValue.npos));
1248  }
1249 
1250  setEdition(Edition(attrValue), rel);
1251  }
1252  else if ( attribute == PoolQueryAttr::complexAttr )
1253  {
1254  try
1255  {
1256  _pimpl->_uncompiledPredicated.insert( AttrMatchData::deserialize( attrValue ) );
1257  }
1258  catch ( const Exception & err )
1259  {
1260  WAR << "Unparsable value for complex: " << err.asUserHistory() << endl;
1261 
1262  }
1263  }
1264  else if ( attribute==PoolQueryAttr::noAttr )
1265  {
1266  WAR << "empty attribute name" << endl;
1267  }
1268  else
1269  {
1270  string s = attrName;
1271  str::replaceAll( s,"_",":" );
1272  SolvAttr a(s);
1273  if ( a == SolvAttr::name || isDependencyAttribute( a ) )
1274  {
1275  Capability c( attrValue );
1276  CapDetail d( c );
1277  if ( d.isVersioned() )
1278  addDependency( a, d.name().asString(), d.op(), d.ed() );
1279  else
1280  addDependency( a, attrValue );
1281  }
1282  else
1283  addAttribute( a, attrValue );
1284  }
1285 
1286  } while ( true );
1287 
1288  return finded_something;
1289  }
1290 
1291  void PoolQuery::serialize( ostream &str, char delim ) const
1292  {
1293  //separating delim
1294  str << delim;
1295  //iterate thrue all settings and write it
1296  static const zypp::PoolQuery q; //not save default options, so create default query example
1297 
1298  for_( it, repos().begin(), repos().end() )
1299  {
1300  str << "repo: " << *it << delim ;
1301  }
1302 
1303  for_( it, kinds().begin(), kinds().end() )
1304  {
1305  str << PoolQueryAttr::kindAttr.asString() << ": "
1306  << it->idStr() << delim ;
1307  }
1308 
1309  if (editionRel() != Rel::ANY && edition() != Edition::noedition)
1310  str << PoolQueryAttr::editionAttr.asString() << ": " << editionRel() << " " << edition() << delim;
1311 
1312  if (matchMode()!=q.matchMode())
1313  {
1314  switch( matchMode() )
1315  {
1316  case Match::STRING:
1317  str << PoolQueryAttr::stringTypeAttr.asString() << ": exact" << delim;
1318  break;
1319  case Match::SUBSTRING:
1321  << ": substring" << delim;
1322  break;
1323  case Match::GLOB:
1324  str << PoolQueryAttr::stringTypeAttr.asString() << ": glob" << delim;
1325  break;
1326  case Match::REGEX:
1327  str << PoolQueryAttr::stringTypeAttr.asString() << ": regex" << delim;
1328  break;
1329  default:
1330  WAR << "unknown match type " << matchMode() << endl;
1331  }
1332  }
1333 
1334  if( caseSensitive() != q.caseSensitive() )
1335  {
1336  str << "case_sensitive: ";
1337  if (caseSensitive())
1338  {
1339  str << "on" << delim;
1340  }
1341  else
1342  {
1343  str << "off" << delim;
1344  }
1345  }
1346 
1347  if( requireAll() != q.requireAll() )
1348  {
1349  str << "require_all: ";
1350  if (requireAll())
1351  {
1352  str << "on" << delim;
1353  }
1354  else
1355  {
1356  str << "off" << delim;
1357  }
1358  }
1359 
1360  if( statusFilterFlags() != q.statusFilterFlags() )
1361  {
1362  switch( statusFilterFlags() )
1363  {
1364  case ALL:
1365  str << "install_status: all" << delim;
1366  break;
1367  case INSTALLED_ONLY:
1368  str << "install_status: installed" << delim;
1369  break;
1370  case UNINSTALLED_ONLY:
1371  str << "install_status: not-installed" << delim;
1372  break;
1373  }
1374  }
1375 
1376  for_( it, strings().begin(), strings().end() )
1377  {
1378  str << PoolQueryAttr::stringAttr.asString()<< ": " << *it << delim;
1379  }
1380 
1381  for_( it, attributes().begin(), attributes().end() )
1382  {
1383  string s = it->first.asString();
1384  str::replaceAll(s,":","_");
1385  for_( it2,it->second.begin(),it->second.end() )
1386  {
1387  str << s <<": "<< *it2 << delim;
1388  }
1389  }
1390 
1391  for_( it, _pimpl->_uncompiledPredicated.begin(), _pimpl->_uncompiledPredicated.end() )
1392  {
1393  str << "complex: "<< it->serialize() << delim;
1394  }
1395 
1396  //separating delim - protection
1397  str << delim;
1398  }
1399 
1400  string PoolQuery::asString() const
1401  { return _pimpl->asString(); }
1402 
1403  ostream & operator<<( ostream & str, const PoolQuery & obj )
1404  { return str << obj.asString(); }
1405 
1406  std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj )
1407  { return dumpRange( str << obj, obj.begin(), obj.end() ); }
1408 
1409  bool PoolQuery::operator==( const PoolQuery & rhs ) const
1410  { return *_pimpl == *rhs._pimpl; }
1411 
1413  namespace detail
1414  {
1415 
1417  //
1418  // CLASS NAME : PoolQueryMatcher
1419  //
1437  {
1438  public:
1440 
1441  public:
1442  const base_iterator & end() const
1443  {
1444  static base_iterator _end;
1445  return _end;
1446  }
1447 
1448  bool advance( base_iterator & base_r ) const
1449  {
1450  if ( base_r == end() )
1451  base_r = startNewQyery(); // first candidate
1452  else
1453  {
1454  base_r.nextSkipSolvable(); // assert we don't visit this Solvable again
1455  ++base_r; // advance to next candidate
1456  }
1457 
1458  while ( base_r != end() )
1459  {
1460  if ( isAMatch( base_r ) )
1461  return true;
1462  // No match: try next
1463  ++base_r;
1464  }
1465  return false;
1466  }
1467 
1471  void matchDetail( const base_iterator & base_r, std::vector<base_iterator> & return_r ) const
1472  {
1473  if ( base_r == end() )
1474  return;
1475 
1476  sat::Solvable inSolvable( base_r.inSolvable() );
1477 
1478  if ( _attrMatchList.size() == 1 )
1479  {
1480  // base_r is already on the 1st matching attribute!
1481  // String matching is done by the base iterator. We must check the predicate here.
1482  // Let's see if there are more matches for this solvable:
1483  base_iterator base( base_r );
1484  base.stayInThisSolvable(); // avoid discarding matches we found far away from here.
1485  return_r.push_back( base );
1486 
1487  const AttrMatchData::Predicate & predicate( _attrMatchList.front().predicate );
1488  for ( ++base; base.inSolvable() == inSolvable; ++base ) // safe even if base == end()
1489  {
1490  if ( ! predicate || predicate( base ) )
1491  return_r.push_back( base );
1492  }
1493  }
1494  else
1495  {
1496  // Here: search all attributes ;(
1497  for_( mi, _attrMatchList.begin(), _attrMatchList.end() )
1498  {
1499  const AttrMatchData & matchData( *mi );
1500  sat::LookupAttr q( matchData.attr, inSolvable );
1501  if ( matchData.strMatcher ) // an empty searchstring matches always
1502  q.setStrMatcher( matchData.strMatcher );
1503 
1504  if ( ! q.empty() ) // there are matches.
1505  {
1506  // now check any predicate:
1507  const AttrMatchData::Predicate & predicate( matchData.predicate );
1508  for_( it, q.begin(), q.end() )
1509  {
1510  if ( ! predicate || predicate( it ) )
1511  return_r.push_back( it );
1512  }
1513  }
1514  }
1515  }
1516  }
1517 
1518  public:
1522  PoolQueryMatcher( const shared_ptr<const PoolQuery::Impl> & query_r )
1523  {
1524  query_r->compile();
1525 
1526  // Repo restriction:
1527  sat::Pool satpool( sat::Pool::instance() );
1528 
1529  for_( it, query_r->_repos.begin(), query_r->_repos.end() )
1530  {
1531  Repository r( satpool.reposFind( *it ) );
1532  if ( r )
1533  _repos.insert( r );
1534  else
1535  _neverMatchRepo = true;
1536  }
1537  // _neverMatchRepo: we just need to catch the case that no repo
1538  // matched, so we'd interpret the empty list as 'take from all'
1539  if ( _neverMatchRepo && ! _repos.empty() )
1540  _neverMatchRepo = false;
1541 
1542  // Kind restriction:
1543  _kinds = query_r->_kinds;
1544  // Edition restriction:
1545  _op = query_r->_op;
1546  _edition = query_r->_edition;
1547  // Status restriction:
1548  _status_flags = query_r->_status_flags;
1549  // StrMatcher
1550  _attrMatchList = query_r->_attrMatchList;
1551  }
1552 
1554  {}
1555 
1556  private:
1559  {
1560  sat::LookupAttr q;
1561 
1562  if ( _neverMatchRepo )
1563  return q.end();
1564 
1565  // Repo restriction:
1566  if ( _repos.size() == 1 )
1567  q.setRepo( *_repos.begin() );
1568  // else: handled in isAMatch.
1569 
1570  // Attribute restriction:
1571  if ( _attrMatchList.size() == 1 ) // all (SolvAttr::allAttr) or 1 attr
1572  {
1573  const AttrMatchData & matchData( _attrMatchList.front() );
1574  q.setAttr( matchData.attr );
1575  if ( matchData.strMatcher ) // empty searchstring matches always
1576  q.setStrMatcher( matchData.strMatcher );
1577  }
1578  else // more than 1 attr (but not all)
1579  {
1580  // no restriction, it's all handled in isAMatch.
1582  }
1583 
1584  return q.begin();
1585  }
1586 
1587 
1598  bool isAMatch( base_iterator & base_r ) const
1599  {
1601  Repository inRepo( base_r.inRepo() );
1602  // Status restriction:
1603  if ( _status_flags
1604  && ( (_status_flags == PoolQuery::INSTALLED_ONLY) != inRepo.isSystemRepo() ) )
1605  {
1606  base_r.nextSkipRepo();
1607  return false;
1608  }
1609  // Repo restriction:
1610  if ( _repos.size() > 1 && _repos.find( inRepo ) == _repos.end() )
1611  {
1612  base_r.nextSkipRepo();
1613  return false;
1614  }
1616  sat::Solvable inSolvable( base_r.inSolvable() );
1617  // Kind restriction:
1618  if ( ! _kinds.empty() && ! inSolvable.isKind( _kinds.begin(), _kinds.end() ) )
1619  {
1620  base_r.nextSkipSolvable();
1621  return false;
1622  }
1623 
1624  // Edition restriction:
1625  if ( _op != Rel::ANY && !compareByRel( _op, inSolvable.edition(), _edition, Edition::Match() ) )
1626  {
1627  base_r.nextSkipSolvable();
1628  return false;
1629  }
1631  // string and predicate matching:
1632 
1633  if ( _attrMatchList.size() == 1 )
1634  {
1635  // String matching was done by the base iterator.
1636  // Now check any predicate:
1637  const AttrMatchData::Predicate & predicate( _attrMatchList.front().predicate );
1638  if ( ! predicate || predicate( base_r ) )
1639  return true;
1640 
1641  return false; // no skip as there may be more occurrences od this attr.
1642  }
1643 
1644  // Here: search all attributes ;(
1645  for_( mi, _attrMatchList.begin(), _attrMatchList.end() )
1646  {
1647  const AttrMatchData & matchData( *mi );
1648  sat::LookupAttr q( matchData.attr, inSolvable );
1649  if ( matchData.strMatcher ) // an empty searchstring matches always
1650  q.setStrMatcher( matchData.strMatcher );
1651 
1652  if ( ! q.empty() ) // there are matches.
1653  {
1654  // now check any predicate:
1655  const AttrMatchData::Predicate & predicate( matchData.predicate );
1656  if ( predicate )
1657  {
1658  for_( it, q.begin(), q.end() )
1659  {
1660  if ( predicate( it ) )
1661  return true;
1662  }
1663  }
1664  else
1665  return true;
1666  }
1667  }
1668  base_r.nextSkipSolvable();
1669  return false;
1670  }
1671 
1672  private:
1674  std::set<Repository> _repos;
1677  std::set<ResKind> _kinds;
1684  AttrMatchList _attrMatchList;
1685  };
1687 
1689  {
1690  // matcher restarts if at end! It is called from the ctor
1691  // to get the 1st match. But if the end is reached, it should
1692  // be deleted, otherwise we'd start over again.
1693  if ( !_matcher )
1694  return; // at end
1695  if ( _matches )
1696  _matches.reset(); // invalidate old matches
1697  if ( ! _matcher->advance( base_reference() ) )
1698  _matcher.reset();
1699  }
1700 
1702  {
1703  if ( _matches )
1704  return *_matches;
1705 
1706  if ( !_matcher )
1707  {
1708  // at end of query:
1709  static const Matches _none;
1710  return _none;
1711  }
1712 
1713  _matches.reset( new Matches );
1714  _matcher->matchDetail( base_reference(), *_matches );
1715  return *_matches;
1716  }
1717 
1718  std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj )
1719  {
1720  str << *obj;
1721  if ( ! obj.matchesEmpty() )
1722  {
1723  for_( it, obj.matchesBegin(), obj.matchesEnd() )
1724  {
1725  str << endl << " " << it->inSolvAttr() << "\t" << it->asString();
1726  }
1727  }
1728  return str;
1729  }
1730 
1732  } //namespace detail
1734 
1736  {
1737  return shared_ptr<detail::PoolQueryMatcher>( new detail::PoolQueryMatcher( _pimpl.getPtr() ) );
1738  }
1739 
1741 } // namespace zypp
1743 
const Rel editionRel() const
Definition: PoolQuery.cc:960
int _status_flags
Installed status filter flags.
Definition: PoolQuery.cc:1682
Interface to gettext.
static const PoolQueryAttr installStatusAttr
Definition: PoolQuery.cc:1057
Rel _op
Operator for edition condition.
Definition: PoolQuery.cc:391
void appendEscaped(std::string &str_r, const C_Str &next_r, const char sep_r= ' ')
Escape next_r and append it to str_r using separator sep_r.
Definition: String.h:712
A Solvable object within the sat Pool.
Definition: Solvable.h:55
void setUninstalledOnly()
Return only packages from repos other than .
Definition: PoolQuery.cc:932
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:162
Arch _arch
Definition: PoolQuery.cc:102
static const StringTypeAttr substringAttr
Definition: PoolQuery.cc:1089
bool advance(base_iterator &base_r) const
Definition: PoolQuery.cc:1448
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:854
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
std::set< ResKind > Kinds
Definition: PoolQuery.h:93
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
String matching option flags as used e.g.
Definition: StrMatcher.h:32
static const SolvAttr allAttr
Value to request searching all Attributes (0).
Definition: SolvAttr.h:46
bool operator!=(const CountryCode &lhs, const CountryCode &rhs)
std::set< ResKind > _kinds
Resolvable kinds to include.
Definition: PoolQuery.cc:1677
Helper providing more detailed information about a Capability.
Definition: Capability.h:289
PoolQuery::StrContainer & _cont
Definition: PoolQuery.cc:466
std::ostream & dumpOn(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.cc:1718
bool operator==(const PoolQuery::Impl &rhs) const
Definition: PoolQuery.cc:402
Architecture.
Definition: Arch.h:36
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:943
static const StringTypeAttr noAttr
Definition: PoolQuery.cc:1086
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:951
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:511
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:926
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
Relational operators.
Definition: Rel.h:43
static const PoolQueryAttr caseSensitiveAttr
Definition: PoolQuery.cc:1056
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:1017
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:851
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:978
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1409
Lightweight attribute value lookup.
Definition: LookupAttr.h:111
Rel _op
Edition filter.
Definition: PoolQuery.cc:1679
const Edition edition() const
Definition: PoolQuery.cc:958
Regular Expression.
Definition: StrMatcher.h:48
sat::SolvAttr attr
Definition: PoolQuery.cc:303
bool operator()(const string &str)
Definition: PoolQuery.cc:460
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:917
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:916
const Arch Arch_empty(IdString::Empty)
bool recover(std::istream &str, char delim= '\n')
Reads from stream query.
Definition: PoolQuery.cc:1108
const Matches & matches() const
Definition: PoolQuery.cc:1701
int invokeOnEach(_Iterator begin_r, _Iterator end_r, _Filter filter_r, _Function fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30
bool operator!=(const PoolQuery::Impl &rhs) const
Definition: PoolQuery.cc:430
PoolQueryMatcher(const shared_ptr< const PoolQuery::Impl > &query_r)
Ctor stores the PoolQuery settings.
Definition: PoolQuery.cc:1522
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query &quot;name|global op edition&quot;.
Definition: PoolQuery.cc:857
Capability _cap
Definition: PoolQuery.cc:160
Access to the sat-pools string space.
Definition: IdString.h:39
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:975
Match _flags
Sat solver search flags.
Definition: PoolQuery.cc:381
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:848
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
Store PoolQuery settings and assist PoolQueryIterator.
Definition: PoolQuery.cc:1436
static const Rel ANY
Definition: Rel.h:56
Edition _edition
Edition condition operand.
Definition: PoolQuery.cc:389
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:973
bool empty() const
Test for an empty Arch (this is Arch_epmty, not Arch_noarch ).
Definition: Arch.h:63
Base class for creating IdString based types.
Definition: IdStringType.h:86
PoolQueryAttr(const std::string &str_r)
Definition: PoolQuery.cc:1043
unsigned splitEscaped(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Definition: String.h:446
const StrContainer & repos() const
Definition: PoolQuery.cc:969
std::string asString() const
Conversion to std::string
Definition: IdString.h:83
Unknown match mode.
Definition: StrMatcher.h:257
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition: String.cc:304
static const PoolQueryAttr noAttr
Definition: PoolQuery.cc:1048
bool requireAll() const
Whether all values added via addString() or addAttribute() are required to match the values of the re...
Definition: PoolQuery.cc:991
bool overlaps(Rel lhs, Rel rhs, int cmp)
Compute Range overlaps.
Definition: Range.cc:30
static const PoolQueryAttr repoAttr
Definition: PoolQuery.cc:1051
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:519
AttrMatchList _attrMatchList
StrMatcher per attribtue.
Definition: PoolQuery.cc:1684
Edition::MatchRange _range
Definition: PoolQuery.cc:101
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:421
std::string getline(std::istream &str)
Read one line from stream.
Definition: IOStream.cc:33
unsigned int size_type
Definition: PoolQuery.h:98
StringTypeAttr(const char *cstr_r)
Definition: PoolQuery.cc:1081
static Pool instance()
Singleton ctor.
Definition: Pool.h:51
Solvable attribute keys.
Definition: SolvAttr.h:40
std::ostream & dumpRange(std::ostream &str, _Iterator begin, _Iterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:91
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:239
bool isModeGlob() const
Whether this has mode GLOB.
Definition: StrMatcher.h:176
bool isVersioned() const
Definition: Capability.h:328
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:934
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
match functor.
Definition: Edition.h:160
void matchDetail(const base_iterator &base_r, std::vector< base_iterator > &return_r) const
Provide all matching attributes within this solvable.
Definition: PoolQuery.cc:1471
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:204
std::string asString() const
Definition: IdStringType.h:106
bool matchWord() const
Definition: PoolQuery.cc:988
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:838
static string wildcards2regex(const string &str)
Converts &#39;*&#39; and &#39;?&#39; wildcards within str into their regex equivalents.
Definition: PoolQuery.cc:658
const AttrRawStrMap & attributes() const
Map (map&lt;SolvAttr, StrContainer&gt;) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:947
void setModeRegex()
Set the mode REGEX.
Definition: StrMatcher.h:201
bool compareByRel(Rel op, const _Tp &lhs, const _Tp &rhs, _Compare compare)
Comparison of two elements using relational operator op.
Definition: RelCompare.h:108
Solvable inSolvable() const
The current Solvable.
Definition: LookupAttr.cc:354
void setMatchWord()
Set to match words (uses regex)
Definition: PoolQuery.cc:918
#define WAR
Definition: Logger.h:48
std::ostream & operator<<(std::ostream &str, const ::_Dataiterator *obj)
Definition: LookupAttr.cc:799
void stayInThisSolvable()
Stop after all matches in the current Solvable are processed.
Definition: LookupAttr.cc:369
Match substring.
Definition: StrMatcher.h:46
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition: Pool.cc:123
bool isAMatch(base_iterator &base_r) const
Check whether we are on a match.
Definition: PoolQuery.cc:1598
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
MyInserter(PoolQuery::StrContainer &cont)
Definition: PoolQuery.cc:458
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:924
sat::LookupAttr::iterator base_iterator
Definition: PoolQuery.cc:1439
bool matchExact() const
Definition: PoolQuery.cc:983
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition: LookupAttr.cc:363
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:435
StringTypeAttr(const std::string &str_r)
Definition: PoolQuery.cc:1083
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off.
Definition: String.cc:78
Kinds _kinds
Kinds to search.
Definition: PoolQuery.cc:397
void setInstalledOnly()
Return only repo packages.
Definition: PoolQuery.cc:930
static const StringTypeAttr exactAttr
Definition: PoolQuery.cc:1088
base_iterator startNewQyery() const
Initialize a new base query.
Definition: PoolQuery.cc:1558
static const PoolQueryAttr stringTypeAttr
Definition: PoolQuery.cc:1054
static const StringTypeAttr wordAttr
Definition: PoolQuery.cc:1092
SolvableIdType size_type
Definition: PoolMember.h:99
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
Repository inRepo() const
The current Repository.
Definition: LookupAttr.cc:351
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
bool matchGlob() const
Definition: PoolQuery.cc:985
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:914
represents all atributes in PoolQuery except SolvAtributes, which are used as is (not needed extend a...
Definition: PoolQuery.cc:1029
for_use_in_switch _op
The operator.
Definition: Rel.h:154
#define arrayEnd(A)
Definition: Easy.h:42
#define arrayBegin(A)
Simple C-array iterator.
Definition: Easy.h:40
bool strToTrue(const C_Str &str)
Parsing boolean from string.
Definition: String.cc:61
std::set< Repository > _repos
Repositories include in the search.
Definition: PoolQuery.cc:1674
std::string predicateStr
Definition: PoolQuery.cc:306
static const PoolQueryAttr stringAttr
Definition: PoolQuery.cc:1053
bool deserialize(const std::string &str_r, DownloadMode &result_r)
Definition: DownloadMode.cc:23
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
bool matchSubstring() const
Definition: PoolQuery.cc:984
std::set< AttrMatchData > _uncompiledPredicated
Uncompiled attributes with predicate.
Definition: PoolQuery.cc:378
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:994
static const Match NOCASE
If set, match case insensitive.
Definition: StrMatcher.h:59
Meta-data query API.
Definition: PoolQuery.h:90
Base class for Exception.
Definition: Exception.h:143
const Kinds & kinds() const
Definition: PoolQuery.cc:965
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:997
static const PoolQueryAttr complexAttr
Definition: PoolQuery.cc:1059
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:908
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:915
bool matchRegex() const
Definition: PoolQuery.cc:986
A sat capability.
Definition: Capability.h:59
Excat matching.
Definition: StrMatcher.h:43
#define WB
Predicate predicate
Definition: PoolQuery.cc:305
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:600
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition: LookupAttr.cc:366
bool isSimple() const
Definition: Capability.h:329
StrContainer _repos
Repos to search.
Definition: PoolQuery.cc:394
Global sat-pool.
Definition: Pool.h:42
bool operator()(const string &str)
Definition: PoolQuery.cc:472
Mode mode() const
Return the mode part.
Definition: StrMatcher.cc:51
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:75
Edition ed() const
Definition: Capability.h:338
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:1004
shared_ptr< Matches > _matches
Definition: PoolQuery.h:601
DefaultIntegral< bool, false > _neverMatchRepo
Definition: PoolQuery.cc:1675
static const PoolQueryAttr requireAllAttr
Definition: PoolQuery.cc:1055
void serialize(std::ostream &str, char delim= '\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1291
static const PoolQueryAttr editionAttr
Definition: PoolQuery.cc:1058
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Rel.h:141
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
Definition: PoolQuery.cc:980
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:481
AttrMatchList _attrMatchList
StrMatcher per attribtue.
Definition: PoolQuery.cc:441
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1735
StatusFilter _status_flags
Sat solver status flags.
Definition: PoolQuery.cc:386
PoolQueryAttr(const char *cstr_r)
Definition: PoolQuery.cc:1039
Impl * clone() const
clone for RWCOW_pointer
Definition: PoolQuery.cc:450
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:616
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:315
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1400
Resolvable kinds.
Definition: ResKind.h:35
static const PoolQueryAttr kindAttr
Definition: PoolQuery.cc:1052
std::string asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:125
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
Rel op() const
Definition: Capability.h:337
static const Match FILES
LookupAttr: match full path when matching in filelists, otherwise just the basenames.
Definition: StrMatcher.h:75
StrContainer _strings
Raw search strings.
Definition: PoolQuery.cc:374
StrMatcher strMatcher
Definition: PoolQuery.cc:304
IdString name() const
Definition: Capability.h:336
static const StringTypeAttr globAttr
Definition: PoolQuery.cc:1091
AttrRawStrMap _attrs
Raw attributes.
Definition: PoolQuery.cc:376
static const Edition noedition
Value representing noedition (&quot;&quot;) This is in fact a valid Edition.
Definition: Edition.h:73
Something else.
Definition: StrMatcher.h:49
const base_iterator & end() const
Definition: PoolQuery.cc:1442
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
static const StringTypeAttr regexAttr
Definition: PoolQuery.cc:1090
bool isModeString() const
Whether this has mode STRING.
Definition: StrMatcher.h:164
void setRequireAll(bool require_all=true)
Require that all of the values set by addString or addAttribute match the values of respective attrib...
Definition: PoolQuery.cc:938