libzypp  15.27.0
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 TPredicate>
213  void addPredicate( const TPredicate & 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  , _status_flags(ALL)
361  {}
362 
364  {}
365 
366  public:
368  string asString() const;
369 
377  std::set<AttrMatchData> _uncompiledPredicated;
378 
382 
385 
390 
393 
397 
398  public:
399 
400  bool operator<( const PoolQuery::Impl & rhs ) const
401  {
402 #define OUTS(A) if ( A != rhs.A ) return A < rhs.A;
403  OUTS( _strings );
404  OUTS( _attrs );
405  OUTS( _uncompiledPredicated );
406  OUTS( _flags.get() );
407  OUTS( _match_word );
408  OUTS( _status_flags );
409  OUTS( _edition );
410  OUTS( _op.inSwitch() );
411  OUTS( _repos );
412  OUTS( _kinds );
413 #undef OUTS
414  return false;
415  }
416 
417  bool operator==( const PoolQuery::Impl & rhs ) const
418  {
419  if ( _flags == rhs._flags
420  // bnc#792901: while libzypp uses exact match mode for a single
421  // package name lock, zypper always uses glob. :(
422  // We unify those two forms to enable zypper to remove zypp locks
423  // without need to actually evaluate the query (which would require
424  // repos to be loaded).
425  || ( ( ( _flags.isModeString() && rhs._flags.isModeGlob() )
426  || ( _flags.isModeGlob() && rhs._flags.isModeString() ) )
427  && _strings.empty()
428  && _attrs.size() == 1
429  && _attrs.begin()->first == sat::SolvAttr::name ) )
430  {
431  return ( _strings == rhs._strings
432  && _attrs == rhs._attrs
433  && _uncompiledPredicated == rhs._uncompiledPredicated
434  && _match_word == rhs._match_word
435  && _status_flags == rhs._status_flags
436  && _edition == rhs._edition
437  && _op == rhs._op
438  && _repos == rhs._repos
439  && _kinds == rhs._kinds );
440  }
441  return false;
442  }
443 
444  bool operator!=( const PoolQuery::Impl & rhs ) const
445  { return ! operator==( rhs ); }
446 
447  public:
452  void compile() const;
453 
455  mutable AttrMatchList _attrMatchList;
456 
457  private:
461  StrMatcher joinedStrMatcher( const StrContainer & container_r, const Match & flags_r ) const;
462 
463  private:
464  friend Impl * rwcowClone<Impl>( const Impl * rhs );
466  Impl * clone() const
467  { return new Impl( *this ); }
468  };
469 
471 
472  struct MyInserter
473  {
474  MyInserter(PoolQuery::StrContainer & cont) : _cont(cont) {}
475 
476  bool operator()(const string & str)
477  {
478  _cont.insert(str);
479  return true;
480  }
481 
483  };
484 
485 
486  struct EmptyFilter
487  {
488  bool operator()(const string & str)
489  {
490  return !str.empty();
491  }
492  };
493 
494  void PoolQuery::Impl::compile() const
495  {
496  _attrMatchList.clear();
497 
498  if ( _flags.mode() == Match::OTHER ) // this will never succeed...
500 
501  // 'different' - will have to iterate through all and match by ourselves (slow)
502  // 'same' - will pass the compiled string to dataiterator_init
503  // 'one-attr' - will pass it to dataiterator_init
504  // 'one-non-regex-str' - will pass to dataiterator_init, set flag to SEARCH_STRING or SEARCH_SUBSTRING
505 
506  // // NO ATTRIBUTE
507  // else
508  // for all _strings
509  // create regex; store in rcstrings; if more strings flag regex;
510  if (_attrs.empty())
511  {
512  ; // A default 'query-all' will be added after all sources are processed.
513  }
514 
515  // // ONE ATTRIBUTE
516  // else if _attrs is not empty but it contains just one attr
517  // for all _strings and _attr[key] strings
518  // create regex; flag 'one-attr'; if more strings flag regex;
519  else if (_attrs.size() == 1)
520  {
521  StrContainer joined;
522  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
523  invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
524 
525  _attrMatchList.push_back( AttrMatchData( _attrs.begin()->first, joinedStrMatcher( joined, _flags ) ) );
526  }
527 
528  // // MULTIPLE ATTRIBUTES
529  else
530  {
531  // check whether there are any per-attribute strings
532  bool attrvals_empty = true;
533  for_( ai, _attrs.begin(), _attrs.end() )
534  {
535  if ( ai->second.empty() )
536  continue;
537  for_( it, ai->second.begin(), ai->second.end() )
538  {
539  if ( !it->empty() )
540  {
541  attrvals_empty = false;
542  break;
543  }
544  }
545  if ( ! attrvals_empty )
546  break;
547  }
548 
549  // chceck whether the per-attribute strings are all the same
550  bool attrvals_thesame = true;
551  AttrRawStrMap::const_iterator ai = _attrs.begin();
552  const StrContainer & set1 = ai->second;
553  ++ai;
554  for (; ai != _attrs.end(); ++ai)
555  {
556  StrContainer result;
557  set_difference(
558  set1.begin(), set1.end(),
559  ai->second.begin(), ai->second.end(),
560  inserter(result, result.begin())/*, ltstr()*/);
561  if (!result.empty())
562  {
563  attrvals_thesame = false;
564  break;
565  }
566  }
567 
568  // // THE SAME STRINGS FOR DIFFERENT ATTRS
569  // else if _attrs is not empty but it does not contain strings
570  // for each key in _attrs take all _strings
571  // create regex; store in rcstrings; flag 'same'; if more strings flag regex;
572  if (attrvals_empty || attrvals_thesame)
573  {
574  StrContainer joined;
575  if (attrvals_empty)
576  {
577  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
578  }
579  else
580  {
581  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
582  invokeOnEach(_attrs.begin()->second.begin(), _attrs.begin()->second.end(), EmptyFilter(), MyInserter(joined));
583  }
584 
585  // May use the same StrMatcher for all
586  StrMatcher matcher( joinedStrMatcher( joined, _flags ) );
587  for_( ai, _attrs.begin(), _attrs.end() )
588  {
589  _attrMatchList.push_back( AttrMatchData( ai->first, matcher ) );
590  }
591  }
592 
593  // // DIFFERENT STRINGS FOR DIFFERENT ATTRS
594  // if _attrs is not empty and it contains non-empty vectors with non-empty strings
595  // for each key in _attrs take all _strings + all _attrs[key] strings
596  // create regex; flag 'different'; if more strings flag regex;
597  else
598  {
599  for_(ai, _attrs.begin(), _attrs.end())
600  {
601  StrContainer joined;
602  invokeOnEach(_strings.begin(), _strings.end(), EmptyFilter(), MyInserter(joined));
603  invokeOnEach(ai->second.begin(), ai->second.end(), EmptyFilter(), MyInserter(joined));
604 
605  _attrMatchList.push_back( AttrMatchData( ai->first, joinedStrMatcher( joined, _flags ) ) );
606  }
607  }
608  }
609 
610  // Now handle any predicated queries
611  if ( ! _uncompiledPredicated.empty() )
612  {
613  StrContainer global;
614  invokeOnEach( _strings.begin(), _strings.end(), EmptyFilter(), MyInserter(global) );
615  for_( it, _uncompiledPredicated.begin(), _uncompiledPredicated.end() )
616  {
617  if ( it->strMatcher.flags().mode() == Match::OTHER )
618  {
619  // need to compile:
620  StrContainer joined( global );
621  const std::string & mstr( it->strMatcher.searchstring() );
622  if ( ! mstr.empty() )
623  joined.insert( mstr );
624 
625  // copy and exchange the StrMatcher
626  AttrMatchData nattr( *it );
627  nattr.strMatcher = joinedStrMatcher( joined, _flags );
628  _attrMatchList.push_back( std::move(nattr) );
629  }
630  else
631  {
632  // copy matcher
633  _attrMatchList.push_back( *it );
634  }
635  }
636  }
637 
638  // If no attributes defined at all, then add 'query all'
639  if ( _attrMatchList.empty() )
640  {
641  _attrMatchList.push_back( AttrMatchData( sat::SolvAttr::allAttr, joinedStrMatcher( _strings, _flags ) ) );
642  }
643 
644  // Finally check here, whether all involved regex compile.
645  for_( it, _attrMatchList.begin(), _attrMatchList.end() )
646  {
647  it->strMatcher.compile(); // throws on error
648  }
649  //DBG << asString() << endl;
650  }
651 
653  namespace
654  {
659  std::string rxEscape( std::string str_r, const Match & flags_r )
660  {
661  if ( str_r.empty() || flags_r.isModeRegex() )
662  return str_r;
663 
664  if ( flags_r.isModeGlob() )
665  return str::rxEscapeGlob( std::move(str_r) );
666 
667  return str::rxEscapeStr( std::move(str_r) );
668  }
669  } // namespace
671 
672  StrMatcher PoolQuery::Impl::joinedStrMatcher( const StrContainer & container_r, const Match & flags_r ) const
673  {
674  if ( container_r.empty() )
675  return StrMatcher( std::string(), flags_r );
676 
677  if ( container_r.size() == 1 && !_match_word ) // use RX to match words
678  return StrMatcher( *container_r.begin(), flags_r );
679 
680  // Convert to a regex.
681  // Note: Modes STRING and GLOB match whole strings (anchored ^ $)
682  // SUBSTRING and REGEX match substrings (match_word anchores SUBSTRING \b)
683  Match retflags( flags_r );
684  retflags.setModeRegex();
685  str::Str ret;
686 
687  if ( flags_r.isModeString() || flags_r.isModeGlob() )
688  ret << "^";
689  else if ( _match_word )
690  ret << "\\b";
691 
692  // (..|..|..)
693  char sep = '(';
694  for ( const::std::string & s : container_r )
695  {
696  ret << sep << rxEscape( s, flags_r );
697  if ( sep == '(' )
698  sep = '|';
699  }
700  ret << ')';
701 
702  if ( flags_r.isModeString() || flags_r.isModeGlob() )
703  ret << "$";
704  else if ( _match_word )
705  ret << "\\b";
706 
707  return StrMatcher( ret, retflags );
708  }
709 
711  {
712  ostringstream o;
713 
714  o << "kinds: ";
715  if ( _kinds.empty() )
716  o << "ALL";
717  else
718  {
719  for(Kinds::const_iterator it = _kinds.begin();
720  it != _kinds.end(); ++it)
721  o << *it << " ";
722  }
723  o << endl;
724 
725  o << "repos: ";
726  if ( _repos.empty() )
727  o << "ALL";
728  else
729  {
730  for(StrContainer::const_iterator it = _repos.begin();
731  it != _repos.end(); ++it)
732  o << *it << " ";
733  }
734  o << endl;
735 
736  o << "version: "<< _op << " " << _edition.asString() << endl;
737  o << "status: " << ( _status_flags ? ( _status_flags == INSTALLED_ONLY ? "INSTALLED_ONLY" : "UNINSTALLED_ONLY" )
738  : "ALL" ) << endl;
739 
740  o << "string match flags: " << Match(_flags) << endl;
741 
742  // raw
743  o << "strings: ";
744  for(StrContainer::const_iterator it = _strings.begin();
745  it != _strings.end(); ++it)
746  o << *it << " ";
747  o << endl;
748 
749  o << "attributes: " << endl;
750  for(AttrRawStrMap::const_iterator ai = _attrs.begin(); ai != _attrs.end(); ++ai)
751  {
752  o << "* " << ai->first << ": ";
753  for(StrContainer::const_iterator vi = ai->second.begin();
754  vi != ai->second.end(); ++vi)
755  o << *vi << " ";
756  o << endl;
757  }
758 
759  o << "predicated: " << endl;
760  for_( it, _uncompiledPredicated.begin(), _uncompiledPredicated.end() )
761  {
762  o << "* " << *it << endl;
763  }
764 
765  // compiled
766  o << "last attribute matcher compiled: " << endl;
767  if ( _attrMatchList.empty() )
768  {
769  o << "not yet compiled" << endl;
770  }
771  else
772  {
773  for_( it, _attrMatchList.begin(), _attrMatchList.end() )
774  {
775  o << "* " << *it << endl;
776  }
777  }
778  return o.str();
779  }
780 
782 
784  //
785  // CLASS NAME : PoolQuery
786  //
788 
789  PoolQuery::PoolQuery()
790  : _pimpl(new Impl())
791  {}
792 
794  {}
795 
796  void PoolQuery::addRepo(const std::string &repoalias)
797  {
798  if (repoalias.empty())
799  {
800  WAR << "ignoring an empty repository alias" << endl;
801  return;
802  }
803  _pimpl->_repos.insert(repoalias);
804  }
805 
806  void PoolQuery::addKind(const ResKind & kind)
807  { _pimpl->_kinds.insert(kind); }
808 
809  void PoolQuery::addString(const string & value)
810  { _pimpl->_strings.insert(value); }
811 
812  void PoolQuery::addAttribute(const sat::SolvAttr & attr, const std::string & value)
813  { _pimpl->_attrs[attr].insert(value); }
814 
815  void PoolQuery::addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition )
816  { return addDependency( attr, name, op, edition, Arch_empty ); }
817 
818  void PoolQuery::addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch )
819  {
820  switch ( op.inSwitch() )
821  {
822  case Rel::ANY_e: // no additional constraint on edition.
823  if ( arch.empty() ) // no additional constraint on arch.
824  {
825  addAttribute( attr, name );
826  return;
827  }
828  break;
829 
830  case Rel::NONE_e: // will never match.
831  return;
832 
833  default: // go and add the predicated query (uncompiled)
834  break;
835  }
836 
837  // Match::OTHER indicates need to compile
838  // (merge global search strings into name).
839  AttrMatchData attrMatchData( attr, StrMatcher( name, Match::OTHER ) );
840 
841  if ( isDependencyAttribute( attr ) )
842  attrMatchData.addPredicate( EditionRangePredicate( op, edition, arch ) );
843  else
844  attrMatchData.addPredicate( SolvableRangePredicate( op, edition, arch ) );
845 
846  _pimpl->_uncompiledPredicated.insert( attrMatchData );
847  }
848 
850  {
851  CapDetail cap( cap_r );
852  if ( ! cap.isSimple() ) // will never match.
853  return;
854 
855  // Matches STRING per default. (won't get compiled!)
856  AttrMatchData attrMatchData( attr, StrMatcher( cap.name().asString() ) );
857 
858  if ( isDependencyAttribute( attr ) )
859  attrMatchData.addPredicate( CapabilityMatchPredicate( cap_r ) );
860  else
861  attrMatchData.addPredicate( SolvableRangePredicate( cap.op(), cap.ed() ) );
862 
863  _pimpl->_uncompiledPredicated.insert( attrMatchData );
864  }
865 
866  void PoolQuery::setEdition(const Edition & edition, const Rel & op)
867  {
869  _pimpl->_op = op;
870  }
871 
877 
879  { return _pimpl->_flags; }
880  void PoolQuery::setFlags( const Match & flags )
881  { _pimpl->_flags = flags; }
882 
883 
889  { _pimpl->_status_flags = flags; }
890 
891 
894  { return _pimpl->_strings; }
895 
898  { return _pimpl->_attrs; }
899 
902  {
903  static const PoolQuery::StrContainer nocontainer;
904  AttrRawStrMap::const_iterator it = _pimpl->_attrs.find(attr);
905  return it != _pimpl->_attrs.end() ? it->second : nocontainer;
906  }
907 
909  { return _pimpl->_edition; }
911  { return _pimpl->_op; }
912 
913 
914  const PoolQuery::Kinds &
916  { return _pimpl->_kinds; }
917 
920  { return _pimpl->_repos; }
921 
922 
924  { return !_pimpl->_flags.test( Match::NOCASE ); }
925  void PoolQuery::setCaseSensitive( bool value )
926  { _pimpl->_flags.turn( Match::NOCASE, !value ); }
927 
929  { return _pimpl->_flags.test( Match::FILES ); }
931  { _pimpl->_flags.turn( Match::FILES, value ); }
932 
933  bool PoolQuery::matchExact() const { return _pimpl->_flags.isModeString(); }
935  bool PoolQuery::matchGlob() const { return _pimpl->_flags.isModeGlob(); }
936  bool PoolQuery::matchRegex() const { return _pimpl->_flags.isModeRegex(); }
938 
940  { return _pimpl->_status_flags; }
941 
942  bool PoolQuery::empty() const
943  {
944  try { return begin() == end(); }
945  catch (const Exception & ex) {}
946  return true;
947  }
948 
950  {
951  try
952  {
953  size_type count = 0;
954  for_( it, begin(), end() )
955  ++count;
956  return count;
957  }
958  catch (const Exception & ex) {}
959  return 0;
960  }
961 
963  { invokeOnEach( begin(), end(), fnc); }
964 
965 
966  /*DEPRECATED LEGACY:*/void PoolQuery::setRequireAll( bool ) {}
967  /*DEPRECATED LEGACY:*/bool PoolQuery::requireAll() const { return false; }
968 
970  //
971  // CLASS NAME : PoolQuery::Attr
972  //
977  struct PoolQueryAttr : public IdStringType<PoolQueryAttr>
978  {
979  private:
982  public:
983 
984  //noAttr
986 
987  explicit PoolQueryAttr( const char* cstr_r )
988  : _str( cstr_r )
989  {}
990 
991  explicit PoolQueryAttr( const std::string & str_r )
992  : _str( str_r )
993  {}
994 
995  // unknown atributes
996  static const PoolQueryAttr noAttr;
997 
998  // PoolQuery's own attributes
999  static const PoolQueryAttr repoAttr;
1000  static const PoolQueryAttr kindAttr;
1003  static const PoolQueryAttr requireAllAttr; // LEAGACY: attribute was defined but never implemented.
1008  };
1009 
1011 
1012  const PoolQueryAttr PoolQueryAttr::repoAttr( "repo" );
1013  const PoolQueryAttr PoolQueryAttr::kindAttr( "type" );
1014  const PoolQueryAttr PoolQueryAttr::stringAttr( "query_string" );
1015  const PoolQueryAttr PoolQueryAttr::stringTypeAttr("match_type");
1016  const PoolQueryAttr PoolQueryAttr::requireAllAttr("require_all"); // LEAGACY: attribute was defined but never implemented.
1017  const PoolQueryAttr PoolQueryAttr::caseSensitiveAttr("case_sensitive");
1018  const PoolQueryAttr PoolQueryAttr::installStatusAttr("install_status");
1019  const PoolQueryAttr PoolQueryAttr::editionAttr("version");
1020  const PoolQueryAttr PoolQueryAttr::complexAttr("complex");
1021 
1022  class StringTypeAttr : public IdStringType<PoolQueryAttr>
1023  {
1026 
1027  public:
1029  explicit StringTypeAttr( const char* cstr_r )
1030  : _str( cstr_r ){}
1031  explicit StringTypeAttr( const std::string & str_r )
1032  : _str( str_r ){}
1033 
1034  static const StringTypeAttr noAttr;
1035 
1039  static const StringTypeAttr globAttr;
1040  static const StringTypeAttr wordAttr;
1041  };
1042 
1044 
1046  const StringTypeAttr StringTypeAttr::substringAttr("substring");
1050 
1052 
1053 
1054  //\TODO maybe ctor with stream can be usefull
1055  //\TODO let it throw, let it throw, let it throw.
1056  bool PoolQuery::recover( istream &str, char delim )
1057  {
1058  bool finded_something = false; //indicates some atributes is finded
1059  string s;
1060  do {
1061  if ( str.eof() )
1062  break;
1063 
1064  getline( str, s, delim );
1065 
1066  if ((!s.empty()) && s[0]=='#') //comment
1067  {
1068  continue;
1069  }
1070 
1071  string::size_type pos = s.find(':');
1072  if (s.empty() || pos == s.npos) // some garbage on line... act like blank line
1073  {
1074  if (finded_something) //is first blank line after record?
1075  {
1076  break;
1077  }
1078  else
1079  {
1080  continue;
1081  }
1082  }
1083 
1084  finded_something = true;
1085 
1086  string attrName(str::trim(string(s,0,pos))); // trimmed name of atribute
1087  string attrValue(str::trim(string(s,pos+1,s.npos))); //trimmed value
1088 
1089  PoolQueryAttr attribute( attrName );
1090 
1091  if ( attribute==PoolQueryAttr::repoAttr )
1092  {
1093  addRepo( attrValue );
1094  }
1095  /* some backwards compatibility */
1096  else if ( attribute==PoolQueryAttr::kindAttr || attribute=="kind" )
1097  {
1098  addKind( ResKind(attrValue) );
1099  }
1100  else if ( attribute==PoolQueryAttr::stringAttr
1101  || attribute=="global_string")
1102  {
1103  addString( attrValue );
1104  }
1105  else if ( attribute==PoolQueryAttr::stringTypeAttr
1106  || attribute=="string_type" )
1107  {
1108  StringTypeAttr s(attrValue);
1109  if( s == StringTypeAttr::regexAttr )
1110  {
1111  setMatchRegex();
1112  }
1113  else if ( s == StringTypeAttr::globAttr )
1114  {
1115  setMatchGlob();
1116  }
1117  else if ( s == StringTypeAttr::exactAttr )
1118  {
1119  setMatchExact();
1120  }
1121  else if ( s == StringTypeAttr::substringAttr )
1122  {
1124  }
1125  else if ( s == StringTypeAttr::wordAttr )
1126  {
1127  setMatchWord();
1128  }
1129  else if ( s == StringTypeAttr::noAttr )
1130  {
1131  WAR << "unknown string type " << attrValue << endl;
1132  }
1133  else
1134  {
1135  WAR << "forget recover some attribute defined as String type attribute: " << attrValue << endl;
1136  }
1137  }
1138  else if ( attribute==PoolQueryAttr::requireAllAttr )
1139  {
1140  // LEAGACY: attribute was defined but never implemented.
1141  // Actually it should not occur outside our testcases.
1142  }
1143  else if ( attribute==PoolQueryAttr::caseSensitiveAttr )
1144  {
1145  if ( str::strToTrue(attrValue) )
1146  {
1147  setCaseSensitive(true);
1148  }
1149  else if ( !str::strToFalse(attrValue) )
1150  {
1151  setCaseSensitive(false);
1152  }
1153  else
1154  {
1155  WAR << "unknown boolean value " << attrValue << endl;
1156  }
1157  }
1158  else if ( attribute==PoolQueryAttr::installStatusAttr )
1159  {
1160  if( attrValue == "all" )
1161  {
1163  }
1164  else if( attrValue == "installed" )
1165  {
1166  setInstalledOnly();
1167  }
1168  else if( attrValue == "not-installed" )
1169  {
1171  }
1172  else
1173  {
1174  WAR << "Unknown value for install status " << attrValue << endl;
1175  }
1176  }
1177  else if ( attribute == PoolQueryAttr::editionAttr)
1178  {
1179  string::size_type pos;
1180  Rel rel("==");
1181  if (attrValue.find_first_of("=<>!") == 0)
1182  {
1183  pos = attrValue.find_last_of("=<>");
1184  rel = Rel(attrValue.substr(0, pos+1));
1185  attrValue = str::trim(attrValue.substr(pos+1, attrValue.npos));
1186  }
1187 
1188  setEdition(Edition(attrValue), rel);
1189  }
1190  else if ( attribute == PoolQueryAttr::complexAttr )
1191  {
1192  try
1193  {
1195  }
1196  catch ( const Exception & err )
1197  {
1198  WAR << "Unparsable value for complex: " << err.asUserHistory() << endl;
1199 
1200  }
1201  }
1202  else if ( attribute==PoolQueryAttr::noAttr )
1203  {
1204  WAR << "empty attribute name" << endl;
1205  }
1206  else
1207  {
1208  string s = attrName;
1209  str::replaceAll( s,"_",":" );
1210  SolvAttr a(s);
1211  if ( a == SolvAttr::name || isDependencyAttribute( a ) )
1212  {
1213  Capability c( attrValue );
1214  CapDetail d( c );
1215  if ( d.isVersioned() )
1216  addDependency( a, d.name().asString(), d.op(), d.ed() );
1217  else
1218  addDependency( a, attrValue );
1219  }
1220  else
1221  addAttribute( a, attrValue );
1222  }
1223 
1224  } while ( true );
1225 
1226  return finded_something;
1227  }
1228 
1229  void PoolQuery::serialize( ostream &str, char delim ) const
1230  {
1231  //separating delim
1232  str << delim;
1233  //iterate thrue all settings and write it
1234  static const zypp::PoolQuery q; //not save default options, so create default query example
1235 
1236  for_( it, repos().begin(), repos().end() )
1237  {
1238  str << "repo: " << *it << delim ;
1239  }
1240 
1241  for_( it, kinds().begin(), kinds().end() )
1242  {
1243  str << PoolQueryAttr::kindAttr.asString() << ": "
1244  << it->idStr() << delim ;
1245  }
1246 
1247  if (editionRel() != Rel::ANY && edition() != Edition::noedition)
1248  str << PoolQueryAttr::editionAttr.asString() << ": " << editionRel() << " " << edition() << delim;
1249 
1250  if (matchMode()!=q.matchMode())
1251  {
1252  switch( matchMode() )
1253  {
1254  case Match::STRING:
1255  str << PoolQueryAttr::stringTypeAttr.asString() << ": exact" << delim;
1256  break;
1257  case Match::SUBSTRING:
1259  << ": substring" << delim;
1260  break;
1261  case Match::GLOB:
1262  str << PoolQueryAttr::stringTypeAttr.asString() << ": glob" << delim;
1263  break;
1264  case Match::REGEX:
1265  str << PoolQueryAttr::stringTypeAttr.asString() << ": regex" << delim;
1266  break;
1267  default:
1268  WAR << "unknown match type " << matchMode() << endl;
1269  }
1270  }
1271 
1272  if( caseSensitive() != q.caseSensitive() )
1273  {
1274  str << "case_sensitive: ";
1275  if (caseSensitive())
1276  {
1277  str << "on" << delim;
1278  }
1279  else
1280  {
1281  str << "off" << delim;
1282  }
1283  }
1284 
1285  if( statusFilterFlags() != q.statusFilterFlags() )
1286  {
1287  switch( statusFilterFlags() )
1288  {
1289  case ALL:
1290  str << "install_status: all" << delim;
1291  break;
1292  case INSTALLED_ONLY:
1293  str << "install_status: installed" << delim;
1294  break;
1295  case UNINSTALLED_ONLY:
1296  str << "install_status: not-installed" << delim;
1297  break;
1298  }
1299  }
1300 
1301  for_( it, strings().begin(), strings().end() )
1302  {
1303  str << PoolQueryAttr::stringAttr.asString()<< ": " << *it << delim;
1304  }
1305 
1306  for_( it, attributes().begin(), attributes().end() )
1307  {
1308  string s = it->first.asString();
1309  str::replaceAll(s,":","_");
1310  for_( it2,it->second.begin(),it->second.end() )
1311  {
1312  str << s <<": "<< *it2 << delim;
1313  }
1314  }
1315 
1317  {
1318  str << "complex: "<< it->serialize() << delim;
1319  }
1320 
1321  //separating delim - protection
1322  str << delim;
1323  }
1324 
1325  string PoolQuery::asString() const
1326  { return _pimpl->asString(); }
1327 
1328  ostream & operator<<( ostream & str, const PoolQuery & obj )
1329  { return str << obj.asString(); }
1330 
1331  std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj )
1332  { return dumpRange( str << obj, obj.begin(), obj.end() ); }
1333 
1334  bool PoolQuery::operator==( const PoolQuery & rhs ) const
1335  { return *_pimpl == *rhs._pimpl; }
1336 
1337  bool PoolQuery::operator<( const PoolQuery & rhs ) const
1338  { return *_pimpl < *rhs._pimpl; }
1339 
1341  namespace detail
1342  {
1343 
1345  //
1346  // CLASS NAME : PoolQueryMatcher
1347  //
1365  {
1366  public:
1368 
1369  public:
1370  const base_iterator & end() const
1371  {
1372  static base_iterator _end;
1373  return _end;
1374  }
1375 
1376  bool advance( base_iterator & base_r ) const
1377  {
1378  if ( base_r == end() )
1379  base_r = startNewQyery(); // first candidate
1380  else
1381  {
1382  base_r.nextSkipSolvable(); // assert we don't visit this Solvable again
1383  ++base_r; // advance to next candidate
1384  }
1385 
1386  while ( base_r != end() )
1387  {
1388  if ( isAMatch( base_r ) )
1389  return true;
1390  // No match: try next
1391  ++base_r;
1392  }
1393  return false;
1394  }
1395 
1399  void matchDetail( const base_iterator & base_r, std::vector<base_iterator> & return_r ) const
1400  {
1401  if ( base_r == end() )
1402  return;
1403 
1404  sat::Solvable inSolvable( base_r.inSolvable() );
1405 
1406  if ( _attrMatchList.size() == 1 )
1407  {
1408  // base_r is already on the 1st matching attribute!
1409  // String matching is done by the base iterator. We must check the predicate here.
1410  // Let's see if there are more matches for this solvable:
1411  base_iterator base( base_r );
1412  base.stayInThisSolvable(); // avoid discarding matches we found far away from here.
1413  return_r.push_back( base );
1414 
1415  const AttrMatchData::Predicate & predicate( _attrMatchList.front().predicate );
1416  for ( ++base; base.inSolvable() == inSolvable; ++base ) // safe even if base == end()
1417  {
1418  if ( ! predicate || predicate( base ) )
1419  return_r.push_back( base );
1420  }
1421  }
1422  else
1423  {
1424  // Here: search all attributes ;(
1425  for_( mi, _attrMatchList.begin(), _attrMatchList.end() )
1426  {
1427  const AttrMatchData & matchData( *mi );
1428  sat::LookupAttr q( matchData.attr, inSolvable );
1429  if ( matchData.strMatcher ) // an empty searchstring matches always
1430  q.setStrMatcher( matchData.strMatcher );
1431 
1432  if ( ! q.empty() ) // there are matches.
1433  {
1434  // now check any predicate:
1435  const AttrMatchData::Predicate & predicate( matchData.predicate );
1436  for_( it, q.begin(), q.end() )
1437  {
1438  if ( ! predicate || predicate( it ) )
1439  return_r.push_back( it );
1440  }
1441  }
1442  }
1443  }
1444  }
1445 
1446  public:
1450  PoolQueryMatcher( const shared_ptr<const PoolQuery::Impl> & query_r )
1451  {
1452  query_r->compile();
1453 
1454  // Repo restriction:
1455  sat::Pool satpool( sat::Pool::instance() );
1456 
1457  for_( it, query_r->_repos.begin(), query_r->_repos.end() )
1458  {
1459  Repository r( satpool.reposFind( *it ) );
1460  if ( r )
1461  _repos.insert( r );
1462  else
1463  _neverMatchRepo = true;
1464  }
1465  // _neverMatchRepo: we just need to catch the case that no repo
1466  // matched, so we'd interpret the empty list as 'take from all'
1467  if ( _neverMatchRepo && ! _repos.empty() )
1468  _neverMatchRepo = false;
1469 
1470  // Kind restriction:
1471  _kinds = query_r->_kinds;
1472  // Edition restriction:
1473  _op = query_r->_op;
1474  _edition = query_r->_edition;
1475  // Status restriction:
1476  _status_flags = query_r->_status_flags;
1477  // StrMatcher
1478  _attrMatchList = query_r->_attrMatchList;
1479  }
1480 
1482  {}
1483 
1484  private:
1487  {
1488  sat::LookupAttr q;
1489 
1490  if ( _neverMatchRepo )
1491  return q.end();
1492 
1493  // Repo restriction:
1494  if ( _repos.size() == 1 )
1495  q.setRepo( *_repos.begin() );
1496  // else: handled in isAMatch.
1497 
1498  // Attribute restriction:
1499  if ( _attrMatchList.size() == 1 ) // all (SolvAttr::allAttr) or 1 attr
1500  {
1501  const AttrMatchData & matchData( _attrMatchList.front() );
1502  q.setAttr( matchData.attr );
1503  if ( matchData.strMatcher ) // empty searchstring matches always
1504  q.setStrMatcher( matchData.strMatcher );
1505  }
1506  else // more than 1 attr (but not all)
1507  {
1508  // no restriction, it's all handled in isAMatch.
1510  }
1511 
1512  return q.begin();
1513  }
1514 
1515 
1526  bool isAMatch( base_iterator & base_r ) const
1527  {
1529  Repository inRepo( base_r.inRepo() );
1530  // Status restriction:
1531  if ( _status_flags
1532  && ( (_status_flags == PoolQuery::INSTALLED_ONLY) != inRepo.isSystemRepo() ) )
1533  {
1534  base_r.nextSkipRepo();
1535  return false;
1536  }
1537  // Repo restriction:
1538  if ( _repos.size() > 1 && _repos.find( inRepo ) == _repos.end() )
1539  {
1540  base_r.nextSkipRepo();
1541  return false;
1542  }
1544  sat::Solvable inSolvable( base_r.inSolvable() );
1545  // Kind restriction:
1546  if ( ! _kinds.empty() && ! inSolvable.isKind( _kinds.begin(), _kinds.end() ) )
1547  {
1548  base_r.nextSkipSolvable();
1549  return false;
1550  }
1551 
1552  // Edition restriction:
1553  if ( _op != Rel::ANY && !compareByRel( _op, inSolvable.edition(), _edition, Edition::Match() ) )
1554  {
1555  base_r.nextSkipSolvable();
1556  return false;
1557  }
1559  // string and predicate matching:
1560 
1561  if ( _attrMatchList.size() == 1 )
1562  {
1563  // String matching was done by the base iterator.
1564  // Now check any predicate:
1565  const AttrMatchData::Predicate & predicate( _attrMatchList.front().predicate );
1566  if ( ! predicate || predicate( base_r ) )
1567  return true;
1568 
1569  return false; // no skip as there may be more occurrences od this attr.
1570  }
1571 
1572  // Here: search all attributes ;(
1573  for_( mi, _attrMatchList.begin(), _attrMatchList.end() )
1574  {
1575  const AttrMatchData & matchData( *mi );
1576  sat::LookupAttr q( matchData.attr, inSolvable );
1577  if ( matchData.strMatcher ) // an empty searchstring matches always
1578  q.setStrMatcher( matchData.strMatcher );
1579 
1580  if ( ! q.empty() ) // there are matches.
1581  {
1582  // now check any predicate:
1583  const AttrMatchData::Predicate & predicate( matchData.predicate );
1584  if ( predicate )
1585  {
1586  for_( it, q.begin(), q.end() )
1587  {
1588  if ( predicate( it ) )
1589  return true;
1590  }
1591  }
1592  else
1593  return true;
1594  }
1595  }
1596  base_r.nextSkipSolvable();
1597  return false;
1598  }
1599 
1600  private:
1602  std::set<Repository> _repos;
1605  std::set<ResKind> _kinds;
1612  AttrMatchList _attrMatchList;
1613  };
1615 
1617  {
1618  // matcher restarts if at end! It is called from the ctor
1619  // to get the 1st match. But if the end is reached, it should
1620  // be deleted, otherwise we'd start over again.
1621  if ( !_matcher )
1622  return; // at end
1623  if ( _matches )
1624  _matches.reset(); // invalidate old matches
1625  if ( ! _matcher->advance( base_reference() ) )
1626  _matcher.reset();
1627  }
1628 
1630  {
1631  if ( _matches )
1632  return *_matches;
1633 
1634  if ( !_matcher )
1635  {
1636  // at end of query:
1637  static const Matches _none;
1638  return _none;
1639  }
1640 
1641  _matches.reset( new Matches );
1642  _matcher->matchDetail( base_reference(), *_matches );
1643  return *_matches;
1644  }
1645 
1646  std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj )
1647  {
1648  str << *obj;
1649  if ( ! obj.matchesEmpty() )
1650  {
1651  for_( it, obj.matchesBegin(), obj.matchesEnd() )
1652  {
1653  str << endl << " " << it->inSolvAttr() << "\t" << it->asString();
1654  }
1655  }
1656  return str;
1657  }
1658 
1660  } //namespace detail
1662 
1664  {
1665  return shared_ptr<detail::PoolQueryMatcher>( new detail::PoolQueryMatcher( _pimpl.getPtr() ) );
1666  }
1667 
1669 } // namespace zypp
1671 
const Rel editionRel() const
Definition: PoolQuery.cc:910
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Definition: String.h:577
int _status_flags
Installed status filter flags.
Definition: PoolQuery.cc:1610
Interface to gettext.
static const PoolQueryAttr installStatusAttr
Definition: PoolQuery.cc:1005
Rel _op
Operator for edition condition.
Definition: PoolQuery.cc:389
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:904
A Solvable object within the sat Pool.
Definition: Solvable.h:53
void setUninstalledOnly()
Return only packages from repos other than .
Definition: PoolQuery.cc:886
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:162
Arch _arch
Definition: PoolQuery.cc:102
static const StringTypeAttr substringAttr
Definition: PoolQuery.cc:1037
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
Definition: RelCompare.h:108
bool advance(base_iterator &base_r) const
Definition: PoolQuery.cc:1376
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:812
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:321
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
std::set< ResKind > _kinds
Resolvable kinds to include.
Definition: PoolQuery.cc:1605
Helper providing more detailed information about a Capability.
Definition: Capability.h:298
PoolQuery::StrContainer & _cont
Definition: PoolQuery.cc:482
std::ostream & dumpOn(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.cc:1646
bool operator==(const PoolQuery::Impl &rhs) const
Definition: PoolQuery.cc:417
Architecture.
Definition: Arch.h:36
std::string rxEscapeStr(std::string str_r)
Escape plain STRING str_r for use in a regex (not anchored by "^" or "$").
Definition: String.cc:413
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:893
static const StringTypeAttr noAttr
Definition: PoolQuery.cc:1034
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:901
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:500
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:880
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:297
Relational operators.
Definition: Rel.h:43
static const PoolQueryAttr caseSensitiveAttr
Definition: PoolQuery.cc:1004
bool requireAll() const ZYPP_DEPRECATED
Definition: PoolQuery.cc:967
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:962
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:809
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:928
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1334
Lightweight attribute value lookup.
Definition: LookupAttr.h:107
Rel _op
Edition filter.
Definition: PoolQuery.cc:1607
const Edition edition() const
Definition: PoolQuery.cc:908
Regular Expression.
Definition: StrMatcher.h:48
sat::SolvAttr attr
Definition: PoolQuery.cc:303
bool operator()(const string &str)
Definition: PoolQuery.cc:476
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:875
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:874
const Arch Arch_empty(IdString::Empty)
bool recover(std::istream &str, char delim= '\n')
Reads from stream query.
Definition: PoolQuery.cc:1056
const Matches & matches() const
Definition: PoolQuery.cc:1629
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:136
bool operator!=(const PoolQuery::Impl &rhs) const
Definition: PoolQuery.cc:444
PoolQueryMatcher(const shared_ptr< const PoolQuery::Impl > &query_r)
Ctor stores the PoolQuery settings.
Definition: PoolQuery.cc:1450
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query "name|global op edition".
Definition: PoolQuery.cc:815
Capability _cap
Definition: PoolQuery.cc:160
void setModeGlob()
Set the mode GLOB.
Definition: StrMatcher.h:198
Access to the sat-pools string space.
Definition: IdString.h:41
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:925
Match _flags
Sat solver search flags.
Definition: PoolQuery.cc:380
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:806
#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:1364
static const Rel ANY
Definition: Rel.h:56
Edition _edition
Edition condition operand.
Definition: PoolQuery.cc:387
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:923
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
void setModeSubstring()
Set the mode SUBSTRING.
Definition: StrMatcher.h:195
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
#define OUTS(A)
PoolQueryAttr(const std::string &str_r)
Definition: PoolQuery.cc:991
const StrContainer & repos() const
Definition: PoolQuery.cc:919
std::string asString() const
Conversion to std::string
Definition: IdString.h:91
constPtrType getPtr() const
Definition: PtrTypes.h:349
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:328
static const PoolQueryAttr noAttr
Definition: PoolQuery.cc:996
bool overlaps(Rel lhs, Rel rhs, int cmp)
Compute Range overlaps.
Definition: Range.cc:30
static const PoolQueryAttr repoAttr
Definition: PoolQuery.cc:999
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:508
AttrMatchList _attrMatchList
StrMatcher per attribtue.
Definition: PoolQuery.cc:1612
void turn(const Match &rhs, bool onoff)
Depending on the value of onoff, set or unset flags.
Definition: StrMatcher.h:127
Edition::MatchRange _range
Definition: PoolQuery.cc:101
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:409
std::string getline(std::istream &str)
Read one line from stream.
Definition: IOStream.cc:33
unsigned int size_type
Definition: PoolQuery.h:98
string asString() const
String representation.
Definition: PoolQuery.cc:710
StringTypeAttr(const char *cstr_r)
Definition: PoolQuery.cc:1029
static Pool instance()
Singleton ctor.
Definition: Pool.h:53
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator 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
void setRequireAll(bool require_all=true) ZYPP_DEPRECATED
Definition: PoolQuery.cc:966
Solvable attribute keys.
Definition: SolvAttr.h:40
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:337
std::string rxEscapeGlob(std::string str_r)
Escape GLOB str_r for use in a regex (not anchored by "^" or "$").
Definition: String.cc:418
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:210
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:888
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:1399
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:221
std::string asString() const
Definition: IdStringType.h:106
bool matchWord() const
Definition: PoolQuery.cc:937
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:796
const AttrRawStrMap & attributes() const
Map (map<SolvAttr, StrContainer>) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:897
void setModeRegex()
Set the mode REGEX.
Definition: StrMatcher.h:201
Solvable inSolvable() const
The current Solvable.
Definition: LookupAttr.cc:354
void setMatchWord()
Set substring to match words.
Definition: PoolQuery.cc:876
#define WAR
Definition: Logger.h:65
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:142
bool isAMatch(base_iterator &base_r) const
Check whether we are on a match.
Definition: PoolQuery.cc:1526
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
MyInserter(PoolQuery::StrContainer &cont)
Definition: PoolQuery.cc:474
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:878
sat::LookupAttr::iterator base_iterator
Definition: PoolQuery.cc:1367
bool matchExact() const
Definition: PoolQuery.cc:933
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:446
StringTypeAttr(const std::string &str_r)
Definition: PoolQuery.cc:1031
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off.
Definition: String.cc:80
Kinds _kinds
Kinds to search.
Definition: PoolQuery.cc:395
void setInstalledOnly()
Return only repo packages.
Definition: PoolQuery.cc:884
static const StringTypeAttr exactAttr
Definition: PoolQuery.cc:1036
base_iterator startNewQyery() const
Initialize a new base query.
Definition: PoolQuery.cc:1486
static const PoolQueryAttr stringTypeAttr
Definition: PoolQuery.cc:1002
static const StringTypeAttr wordAttr
Definition: PoolQuery.cc:1040
SolvableIdType size_type
Definition: PoolMember.h:126
std::ostream & operator<<(std::ostream &str, const zypp::shared_ptr< void > &obj)
Definition: PtrTypes.h:134
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 SetRelation::Enum &lhs, const SetCompare &rhs)
bool matchGlob() const
Definition: PoolQuery.cc:935
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:872
represents all atributes in PoolQuery except SolvAtributes, which are used as is (not needed extend a...
Definition: PoolQuery.cc:977
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:63
std::set< Repository > _repos
Repositories include in the search.
Definition: PoolQuery.cc:1602
std::string predicateStr
Definition: PoolQuery.cc:306
bool isModeSubstring() const
Whether this has mode SUBSTRING.
Definition: StrMatcher.h:173
static const PoolQueryAttr stringAttr
Definition: PoolQuery.cc:1001
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:934
std::set< AttrMatchData > _uncompiledPredicated
Uncompiled attributes with predicate.
Definition: PoolQuery.cc:377
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:939
void setModeString()
Set the mode STRING.
Definition: StrMatcher.h:186
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
bool isModeRegex() const
Whether this has mode REGEX.
Definition: StrMatcher.h:179
const Kinds & kinds() const
Definition: PoolQuery.cc:915
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:942
static const PoolQueryAttr complexAttr
Definition: PoolQuery.cc:1007
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:866
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:873
bool matchRegex() const
Definition: PoolQuery.cc:936
A sat capability.
Definition: Capability.h:59
Excat matching.
Definition: StrMatcher.h:43
Predicate predicate
Definition: PoolQuery.cc:305
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:589
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition: LookupAttr.cc:366
bool isSimple() const
Definition: Capability.h:338
StrContainer _repos
Repos to search.
Definition: PoolQuery.cc:392
bool operator<(const PoolQuery::Impl &rhs) const
Definition: PoolQuery.cc:400
Global sat-pool.
Definition: Pool.h:44
bool operator()(const string &str)
Definition: PoolQuery.cc:488
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:75
Edition ed() const
Definition: Capability.h:347
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:949
shared_ptr< Matches > _matches
Definition: PoolQuery.h:590
DefaultIntegral< bool, false > _neverMatchRepo
Definition: PoolQuery.cc:1603
static const PoolQueryAttr requireAllAttr
Definition: PoolQuery.cc:1003
void serialize(std::ostream &str, char delim= '\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1229
static const PoolQueryAttr editionAttr
Definition: PoolQuery.cc:1006
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:930
bool operator<(const PoolQuery &b) const
Definition: PoolQuery.cc:1337
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:470
AttrMatchList _attrMatchList
StrMatcher per attribtue.
Definition: PoolQuery.cc:455
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1663
StatusFilter _status_flags
Sat solver status flags.
Definition: PoolQuery.cc:384
PoolQueryAttr(const char *cstr_r)
Definition: PoolQuery.cc:987
Impl * clone() const
clone for RWCOW_pointer
Definition: PoolQuery.cc:466
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:605
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:316
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1325
Resolvable kinds.
Definition: ResKind.h:32
static const PoolQueryAttr kindAttr
Definition: PoolQuery.cc:1000
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
Rel op() const
Definition: Capability.h:346
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:373
StrMatcher strMatcher
Definition: PoolQuery.cc:304
IdString name() const
Definition: Capability.h:345
static const StringTypeAttr globAttr
Definition: PoolQuery.cc:1039
AttrRawStrMap _attrs
Raw attributes.
Definition: PoolQuery.cc:375
static const Edition noedition
Value representing noedition ("") 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:1370
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
static const StringTypeAttr regexAttr
Definition: PoolQuery.cc:1038
bool isModeString() const
Whether this has mode STRING.
Definition: StrMatcher.h:164
bool test(const Match &rhs) const
Test whether all of the rhs bits are set (same mode if rhs has one).
Definition: StrMatcher.h:101