libzypp: zypp/Capability.cc Source File

libzypp 17.38.5

Capability.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp-core/base/LogTools.h>
14
15#include <zypp-core/base/String.h>
16#include <zypp-core/base/Regex.h>
17#include <zypp-core/base/Gettext.h>
18#include <zypp-core/base/Exception.h>
19
20#include <zypp/Arch.h>
21#include <zypp/Rel.h>
22#include <zypp/Edition.h>
23#include <zypp/Capability.h>
24
25#include <zypp/sat/detail/PoolImpl.h>
26#include <zypp/sat/detail/PoolMember.h>
27#include <zypp/sat/Pool.h>
28#include <zypp/ResPool.h>
29
30using std::endl;
31
33namespace zypp
34{
36 namespace
37 {
38
40 template <unsigned TLen = 5>
41 struct TempStrings
42 {
44 std::string & getNext()
45 { unsigned c = _next; _next = (_next+1) % TLen; _buf[c].clear(); return _buf[c]; }
46
47 private:
48 unsigned _next = 0;
49 std::string _buf[TLen];
50 };
51
53 inline std::string::size_type backskipWs( const std::string & str_r, std::string::size_type pos_r )
54 {
55 for ( ; pos_r != std::string::npos; --pos_r )
56 {
57 char ch = str_r[pos_r];
58 if ( ch != ' ' && ch != '\t' )
59 break;
60 }
61 return pos_r;
62 }
63
65 inline std::string::size_type backskipNWs( const std::string & str_r, std::string::size_type pos_r )
66 {
67 for ( ; pos_r != std::string::npos; --pos_r )
68 {
69 char ch = str_r[pos_r];
70 if ( ch == ' ' || ch == '\t' )
71 break;
72 }
73 return pos_r;
74 }
75
77 void splitOpEdition( std::string & str_r, Rel & op_r, Edition & ed_r )
78 {
79 if ( str_r.empty() )
80 return;
81 std::string::size_type ch( str_r.size()-1 );
82
83 // check whether the one but last word is a valid Rel:
84 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
85 {
86 std::string::size_type ee( ch );
87 if ( (ch = backskipNWs( str_r, ch )) != std::string::npos )
88 {
89 std::string::size_type eb( ch );
90 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
91 {
92 std::string::size_type oe( ch );
93 ch = backskipNWs( str_r, ch ); // now before 'op'? begin
94 if ( op_r.parseFrom( str_r.substr( ch+1, oe-ch ) ) )
95 {
96 // found a legal 'op'
97 ed_r = Edition( str_r.substr( eb+1, ee-eb ) );
98 if ( ch != std::string::npos ) // 'op' is not at str_r begin, so skip WS
99 ch = backskipWs( str_r, ch );
100 str_r.erase( ch+1 );
101 return;
102 }
103 }
104 }
105 }
106 // HERE: Didn't find 'name op edition'
107 // As a convenience we check for an embeded 'op' (not surounded by WS).
108 // But just '[<=>]=?|!=' and not inside '()'.
109 ch = str_r.find_last_of( "<=>)" );
110 if ( ch != std::string::npos && str_r[ch] != ')' )
111 {
112 std::string::size_type oe( ch );
113
114 // do edition first:
115 ch = str_r.find_first_not_of( " \t", oe+1 );
116 if ( ch != std::string::npos )
117 ed_r = Edition( str_r.substr( ch ) );
118
119 // now finish op:
120 ch = oe-1;
121 if ( str_r[oe] != '=' ) // '[<>]'
122 {
123 op_r = ( str_r[oe] == '<' ) ? Rel::LT : Rel::GT;
124 }
125 else
126 { // '?='
127 if ( ch != std::string::npos )
128 {
129 switch ( str_r[ch] )
130 {
131 case '<': --ch; op_r = Rel::LE; break;
132 case '>': --ch; op_r = Rel::GE; break;
133 case '!': --ch; op_r = Rel::NE; break;
134 case '=': --ch; // fall through
135 default: op_r = Rel::EQ; break;
136 }
137 }
138 }
139
140 // finally name:
141 if ( ch != std::string::npos ) // 'op' is not at str_r begin, so skip WS
142 ch = backskipWs( str_r, ch );
143 str_r.erase( ch+1 );
144 return;
145 }
146 // HERE: It's a plain 'name'
147 }
148
151 sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
152 const Arch & arch_r,
153 const std::string & name_r,
154 Rel op_r,
155 const Edition & ed_r,
156 const ResKind & kind_r )
157 {
158 // First build the name, non-packages prefixed by kind
159 sat::Solvable::SplitIdent split( kind_r, name_r );
160 sat::detail::IdType nid( split.ident().id() );
161
162 if ( split.kind() == ResKind::srcpackage )
163 {
164 // map 'kind srcpackage' to 'arch src', the pseudo architecture
165 // libsolv uses.
166 nid = ::pool_rel2id( pool_r, nid, IdString(ARCH_SRC).id(), REL_ARCH, /*create*/true );
167 }
168
169 // Extend name by architecture, if provided and not a srcpackage
170 if ( ! arch_r.empty() && kind_r != ResKind::srcpackage )
171 {
172 nid = ::pool_rel2id( pool_r, nid, arch_r.id(), REL_ARCH, /*create*/true );
173 }
174
175 // Extend 'op edition', if provided
176 if ( op_r != Rel::ANY && ed_r != Edition::noedition )
177 {
178 nid = ::pool_rel2id( pool_r, nid, ed_r.id(), op_r.bits(), /*create*/true );
179 }
180
181 return nid;
182 }
183
187 sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
188 const std::string & name_r, Rel op_r, const Edition & ed_r,
189 const ResKind & kind_r )
190 {
191 static const Arch srcArch( IdString(ARCH_SRC).asString() );
192 static const Arch nosrcArch( IdString(ARCH_NOSRC).asString() );
193 static const std::string srcKindPrefix( ResKind::srcpackage.asString() + ':' );
194
195 // check for an embedded 'srcpackage:foo' to be mapped to 'foo' and 'ResKind::srcpackage'.
196 if ( kind_r.empty() && str::hasPrefix( name_r, srcKindPrefix ) )
197 {
198 return relFromStr( pool_r, Arch_empty, name_r.substr( srcKindPrefix.size() ), op_r, ed_r, ResKind::srcpackage );
199 }
200
201 Arch arch( Arch_empty );
202 std::string name( name_r );
203
204 std::string::size_type asep( name_r.rfind( '.' ) );
205 if ( asep != std::string::npos )
206 {
207 Arch ext( name_r.substr( asep+1 ) );
208 if ( ext.isBuiltIn() || ext == srcArch || ext == nosrcArch )
209 {
210 arch = ext;
211 name.erase( asep );
212 }
213 }
214
215 return relFromStr( pool_r, arch, name, op_r, ed_r, kind_r );
216 }
217
220 sat::detail::IdType relFromStr( sat::detail::CPool * pool_r,
221 const Arch & arch_r, // parse from name if empty
222 const std::string & str_r, const ResKind & kind_r,
223 Capability::CtorFlag flag_r )
224 {
225 std::string name( str_r );
226 Rel op;
227 Edition ed;
228 if ( flag_r == Capability::UNPARSED )
229 {
230 splitOpEdition( name, op, ed );
231 }
232
233 if ( arch_r.empty() )
234 return relFromStr( pool_r, name, op, ed, kind_r ); // parses for name[.arch]
235 // else
236 return relFromStr( pool_r, arch_r, name, op, ed, kind_r );
237 }
238
240 sat::detail::IdType richOrRelFromStr( sat::detail::CPool * pool_r, const std::string & str_r, const ResKind & prefix_r, Capability::CtorFlag flag_r )
241 {
242 if ( str_r[0] == '(' ) {
243 sat::detail::IdType res { sat::detail::PoolMember::myPool().parserpmrichdep( str_r.c_str() ) };
244 if ( res ) return res;
245 // else: no richdep, so fall back to the ordinary parser which in
246 // case of doubt turns the string into a NAMED cap.
247 }
248 return relFromStr( pool_r, Arch_empty, str_r, prefix_r, flag_r );
249 }
250
252 } // namespace
254
255 const Capability Capability::Null( STRID_NULL );
256 const Capability Capability::Empty( STRID_EMPTY );
257
259
260 Capability::Capability( const char * str_r, const ResKind & prefix_r, CtorFlag flag_r )
261 : _id( richOrRelFromStr( myPool().getPool(), str_r, prefix_r, flag_r ) )
262 {}
263
264 Capability::Capability( const std::string & str_r, const ResKind & prefix_r, CtorFlag flag_r )
265 : _id( richOrRelFromStr( myPool().getPool(), str_r, prefix_r, flag_r ) )
266 {}
267
268 Capability::Capability( const Arch & arch_r, const char * str_r, const ResKind & prefix_r, CtorFlag flag_r )
269 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
270 {}
271
272 Capability::Capability( const Arch & arch_r, const std::string & str_r, const ResKind & prefix_r, CtorFlag flag_r )
273 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
274 {}
275
276 Capability::Capability( const char * str_r, CtorFlag flag_r, const ResKind & prefix_r )
277 : _id( relFromStr( myPool().getPool(), Arch_empty, str_r, prefix_r, flag_r ) )
278 {}
279
280 Capability::Capability( const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r )
281 : _id( relFromStr( myPool().getPool(), Arch_empty, str_r, prefix_r, flag_r ) )
282 {}
283
284 Capability::Capability( const Arch & arch_r, const char * str_r, CtorFlag flag_r, const ResKind & prefix_r )
285 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
286 {}
287
288 Capability::Capability( const Arch & arch_r, const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r )
289 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
290 {}
291
293 // Ctor from <name[.arch] op edition>.
295
296 Capability::Capability( const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r )
297 : _id( relFromStr( myPool().getPool(), name_r, Rel(op_r), Edition(ed_r), prefix_r ) )
298 {}
299 Capability::Capability( const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r )
300 : _id( relFromStr( myPool().getPool(), name_r, op_r, Edition(ed_r), prefix_r ) )
301 {}
302 Capability::Capability( const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r )
303 : _id( relFromStr( myPool().getPool(), name_r, op_r, ed_r, prefix_r ) )
304 {}
305
307 // Ctor from <arch name op edition>.
309
310 Capability::Capability( const std::string & arch_r, const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r )
311 : _id( relFromStr( myPool().getPool(), Arch(arch_r), name_r, Rel(op_r), Edition(ed_r), prefix_r ) )
312 {}
313 Capability::Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r )
314 : _id( relFromStr( myPool().getPool(), Arch(arch_r), name_r, op_r, Edition(ed_r), prefix_r ) )
315 {}
316 Capability::Capability( const std::string & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r )
317 : _id( relFromStr( myPool().getPool(), Arch(arch_r), name_r, op_r, ed_r, prefix_r ) )
318 {}
319 Capability::Capability( const Arch & arch_r, const std::string & name_r, const std::string & op_r, const std::string & ed_r, const ResKind & prefix_r )
320 : _id( relFromStr( myPool().getPool(), arch_r, name_r, Rel(op_r), Edition(ed_r), prefix_r ) )
321 {}
322 Capability::Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const std::string & ed_r, const ResKind & prefix_r )
323 : _id( relFromStr( myPool().getPool(), arch_r, name_r, op_r, Edition(ed_r), prefix_r ) )
324 {}
325 Capability::Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r )
326 : _id( relFromStr( myPool().getPool(), arch_r, name_r, op_r, ed_r, prefix_r ) )
327 {}
328
330 // Ctor creating a namespace: capability.
332
333 Capability::Capability( ResolverNamespace namespace_r, IdString value_r )
334 : _id( ::pool_rel2id( myPool().getPool(), asIdString(namespace_r).id(), (value_r.empty() ? STRID_NULL : value_r.id() ), CAP_NAMESPACE, /*create*/true ) )
335 {}
336
338 // Ctor creating an expression
340
341 Capability::Capability( Capability::CapRel rel_r, const Capability & lhs_r, const Capability & rhs_r )
342 : _id( ::pool_rel2id( myPool().getPool(), lhs_r.id(), rhs_r.id(), rel_r, /*create*/true ) )
343 {}
344
346 // https://rpm-software-management.github.io/rpm/manual/boolean_dependencies.html
347 namespace
348 {
349 inline const char * opstr( int op_r )
350 {
351 switch ( op_r )
352 {
353 case REL_GT: return " > ";
354 case REL_EQ: return " = ";
355 case REL_LT: return " < ";
356 case REL_GT|REL_EQ: return " >= ";
357 case REL_LT|REL_EQ: return " <= ";
358 case REL_GT|REL_LT: return " != ";
359 case REL_GT|REL_LT|REL_EQ: return " <=> ";
360 case REL_AND: return " and ";
361 case REL_OR: return " or ";
362 case REL_COND: return " if ";
363 case REL_UNLESS: return " unless ";
364 case REL_ELSE: return " else ";
365 case REL_WITH: return " with ";
366 case REL_WITHOUT: return " without ";
367 }
368 return "UNKNOWNCAPREL";
369 }
370
371 inline bool isBoolOp( int op_r )
372 {
373 switch ( op_r ) {
374 case REL_AND:
375 case REL_OR:
376 case REL_COND:
377 case REL_UNLESS:
378 case REL_ELSE:
379 case REL_WITH:
380 case REL_WITHOUT:
381 return true;
382 }
383 return false;
384 }
385
386 inline bool needsBrace( int op_r, int parop_r )
387 {
388 return ( isBoolOp( parop_r ) || parop_r == 0 ) && isBoolOp( op_r )
389 && ( parop_r != op_r || op_r == REL_COND || op_r == REL_UNLESS || op_r == REL_ELSE )
390 && not ( ( parop_r == REL_COND || parop_r == REL_UNLESS ) && op_r == REL_ELSE );
391 }
392
393 void cap2strHelper( std::string & outs_r, sat::detail::CPool * pool_r, sat::detail::IdType id_r, int parop_r )
394 {
395 if ( ISRELDEP(id_r) ) {
396 ::Reldep * rd = GETRELDEP( pool_r, id_r );
397 int op = rd->flags;
398
399 if ( op == CapDetail::CAP_ARCH ) {
400 if ( rd->evr == ARCH_SRC || rd->evr == ARCH_NOSRC ) {
401 // map arch .{src,nosrc} to kind srcpackage
402 outs_r += ResKind::srcpackage.c_str();
403 outs_r += ":";
404 outs_r += IdString(rd->name).c_str();
405 return;
406 }
407 cap2strHelper( outs_r, pool_r, rd->name, op );
408 outs_r += ".";
409 cap2strHelper( outs_r, pool_r, rd->evr, op );
410 return;
411 }
412
413 if ( op == CapDetail::CAP_NAMESPACE ) {
414 cap2strHelper( outs_r, pool_r, rd->name, op );
415 outs_r += "(";
416 cap2strHelper( outs_r, pool_r, rd->evr, op );
417 outs_r += ")";
418 return;
419 }
420
421 if ( op == REL_FILECONFLICT )
422 {
423 cap2strHelper( outs_r, pool_r, rd->name, op );
424 return;
425 }
426
427 if ( needsBrace( op, parop_r ) ) {
428 outs_r += "(";
429 cap2strHelper( outs_r, pool_r, rd->name, op );
430 outs_r += opstr( op );
431 cap2strHelper( outs_r, pool_r, rd->evr, op );
432 outs_r += ")";
433 return;
434 }
435
436 cap2strHelper( outs_r, pool_r, rd->name, op );
437 outs_r += opstr( op );
438 cap2strHelper( outs_r, pool_r, rd->evr, op );
439 }
440 else
441 outs_r += IdString(id_r).c_str();
442 }
443 } // namespace
445
446 const char * Capability::c_str() const
447 {
448 if ( not id() ) return "";
449 if ( not ISRELDEP(id()) ) return IdString(id()).c_str();
450
451 static TempStrings<5> tempstrs; // Round Robin buffer to prolong the lifetime of the returned char*
452
453 std::string & outs { tempstrs.getNext() };
454 cap2strHelper( outs, myPool().getPool(), id(), 0 );
455 return outs.c_str();
456 }
457
458 CapMatch Capability::_doMatch( sat::detail::IdType lhs, sat::detail::IdType rhs )
459 {
460 if ( lhs == rhs )
461 return CapMatch::yes;
462
463 CapDetail l( lhs );
464 CapDetail r( rhs );
465
466 switch ( l.kind() )
467 {
468 case CapDetail::NOCAP:
469 return( r.kind() == CapDetail::NOCAP ); // NOCAP matches NOCAP only
470 break;
471 case CapDetail::EXPRESSION:
472 return CapMatch::irrelevant;
473 break;
474 case CapDetail::NAMED:
475 case CapDetail::VERSIONED:
476 break;
477 }
478
479 switch ( r.kind() )
480 {
481 case CapDetail::NOCAP:
482 return CapMatch::no; // match case handled above
483 break;
484 case CapDetail::EXPRESSION:
485 return CapMatch::irrelevant;
486 break;
487 case CapDetail::NAMED:
488 case CapDetail::VERSIONED:
489 break;
490 }
491 // comparing two simple caps:
492 if ( l.name() != r.name() )
493 return CapMatch::no;
494
495 // if both are arch restricted they must match
496 if ( l.arch() != r.arch()
497 && ! ( l.arch().empty() || r.arch().empty() ) )
498 return CapMatch::no;
499
500 // isNamed matches ANY edition:
501 if ( l.isNamed() || r.isNamed() )
502 return CapMatch::yes;
503
504 // both are versioned:
505 return overlaps( Edition::MatchRange( l.op(), l.ed() ),
506 Edition::MatchRange( r.op(), r.ed() ) );
507 }
508
509 bool Capability::isInterestingFileSpec( const char * name_r )
510 {
511 static str::smatch what;
512 static const str::regex filenameRegex(
513 "/(s?bin|lib(64)?|etc)/|^/usr/(games/|share/(dict/words|magic\\.mime)$)|^/opt/gnome/games/",
514 str::regex::nosubs );
515
516 return str::regex_match( name_r, what, filenameRegex );
517 }
518
519 Capability Capability::guessPackageSpec( const std::string & str_r, bool & rewrote_r )
520 {
521 Capability cap( str_r );
522 CapDetail detail( cap.detail() );
523
524 // str_r might be the form "libzypp-1.2.3-4.5(.arch)'
525 // correctly parsed as name capability by the ctor.
526 // TODO: Think about allowing glob char in name - for now don't process
527 if ( detail.isNamed() && !::strpbrk( detail.name().c_str(), "*?[{" )
528 && ::strrchr( detail.name().c_str(), '-' ) && sat::WhatProvides( cap ).empty() )
529 {
530 Arch origArch( detail.arch() ); // to support a trailing .arch
531
532 std::string guess( detail.name().asString() );
533 std::string::size_type pos( guess.rfind( '-' ) );
534 guess[pos] = '=';
535
536 Capability guesscap( origArch, guess );
537 detail = guesscap.detail();
538
539 ResPool pool( ResPool::instance() );
540 // require name part matching a pool items name (not just provides!)
541 if ( pool.byIdentBegin( detail.name() ) != pool.byIdentEnd( detail.name() ) )
542 {
543 rewrote_r = true;
544 return guesscap;
545 }
546
547 // try the one but last '-'
548 if ( pos )
549 {
550 guess[pos] = '-';
551 if ( (pos = guess.rfind( '-', pos-1 )) != std::string::npos )
552 {
553 guess[pos] = '=';
554
555 guesscap = Capability( origArch, guess );
556 detail = guesscap.detail();
557
558 // require name part matching a pool items name (not just provides!)
559 if ( pool.byIdentBegin( detail.name() ) != pool.byIdentEnd( detail.name() ) )
560 {
561 rewrote_r = true;
562 return guesscap;
563 }
564 }
565 }
566 }
567
568 rewrote_r = false;
569 return cap;
570 }
571
572 Capability Capability::guessPackageSpec( const std::string & str_r )
573 {
574 bool dummy = false;
575 return guessPackageSpec( str_r, dummy );
576 }
577
578 /******************************************************************
579 **
580 ** FUNCTION NAME : operator<<
581 ** FUNCTION TYPE : std::ostream &
582 */
583 std::ostream & operator<<( std::ostream & str, const Capability & obj )
584 {
585 return str << obj.c_str();
586 }
587
588 std::ostream & dumpOn( std::ostream & str, const Capability & obj )
589 {
590 return str << ( obj ? ::pool_dep2str( sat::Pool::instance().get(), obj.id() ) : "" );
591 }
592
593 std::ostream & operator<<( std::ostream & str, Capability::CapRel obj )
594 {
595 switch ( obj )
596 {
597 case Capability::CAP_AND: return str << "and"; break; // &
598 case Capability::CAP_OR: return str << "or"; break; // |
599 case Capability::CAP_COND: return str << "if"; break;
600 case Capability::CAP_UNLESS: return str << "unless"; break;
601 case Capability::CAP_ELSE: return str << "else"; break;
602 case Capability::CAP_WITH: return str << "with"; break; // +
603 case Capability::CAP_WITHOUT: return str << "without"; break; // -
604 case Capability::CAP_NAMESPACE: return str << "NAMESPACE"; break;
605 case Capability::CAP_ARCH: return str << "ARCH"; break;
606 }
607 return str << "UnknownCapRel("+str::numstring(obj)+")";
608 }
609
610 std::ostream & dumpCap::dumpOn( std::ostream & str ) const
611 { return _dumpRec( str, _cap ); }
612 std::ostream & dumpCap::_dumpRec( std::ostream & str, Capability cap_r, std::string lvl_r ) const
613 {
614 std::optional<decltype(lvl_r.rbegin())> lastch; // lvl_r last char if not empty
615 if ( not lvl_r.empty() )
616 lastch = lvl_r.rbegin();
617 auto d = cap_r.detail();
618 if ( d.isExpression() ) {
619 static const char* ts = " +|+ ";
620 const char* t = lastch && **lastch == 'l' ? ts : ts+2;
621 if ( lastch ) **lastch = t[0];
622 _dumpRec( str, d.lhs(), lvl_r+" l" ) << endl;
623 if ( lastch ) **lastch = t[1];
624 str << lvl_r << "<" << d.capRel() << endl;
625 if ( lastch ) **lastch = t[2];
626 _dumpRec( str, d.rhs(), lvl_r+" r" );
627 } else {
628 if ( lastch ) **lastch = ' ';
629 str << lvl_r << '"' << d << '"';
630 }
631 return str;
632 }
633
635 //
636 // CLASS NAME : CapDetail
637 //
639
640 void CapDetail::_init()
641 {
642 // : _kind( NOCAP ), _lhs( id_r ), _rhs( 0 ), _flag( 0 ), _archIfSimple( 0 )
643
644 if ( _lhs == sat::detail::emptyId || _lhs == sat::detail::noId )
645 return; // NOCAP
646
647 if ( ! ISRELDEP(_lhs) )
648 {
649 // this is name without arch!
650 _kind = NAMED;
651 return;
652 }
653
654 ::Reldep * rd = GETRELDEP( myPool().getPool(), _lhs );
655 _lhs = rd->name;
656 _rhs = rd->evr;
657 _flag = rd->flags;
658
659 if ( Rel::isRel( _flag ) )
660 {
661 _kind = VERSIONED;
662 // Check for name.arch...
663 if ( ! ISRELDEP(_lhs) )
664 return; // this is name without arch!
665 rd = GETRELDEP( myPool().getPool(), _lhs );
666 if ( rd->flags != CAP_ARCH )
667 return; // this is not name.arch
668 // This is name.arch:
669 _lhs = rd->name;
670 _archIfSimple = rd->evr;
671 }
672 else if ( rd->flags == CAP_ARCH )
673 {
674 _kind = NAMED;
675 // This is name.arch:
676 _lhs = rd->name;
677 _archIfSimple = rd->evr;
678 }
679 else
680 {
681 _kind = EXPRESSION;
682 return;
683 }
684 // map back libsolvs pseudo arch 'src' to kind srcpackage
685 if ( _archIfSimple == ARCH_SRC || _archIfSimple == ARCH_NOSRC )
686 {
687 _lhs = IdString( (ResKind::srcpackage.asString() + ":" + IdString(_lhs).c_str()).c_str() ).id();
688 _archIfSimple = 0;
689 }
690 }
691
692 /******************************************************************
693 **
694 ** FUNCTION NAME : operator<<
695 ** FUNCTION TYPE : std::ostream &
696 */
697 std::ostream & operator<<( std::ostream & str, const CapDetail & obj )
698 {
699 static const char archsep = '.';
700 switch ( obj.kind() )
701 {
702 case CapDetail::NOCAP:
703 return str << "<NoCap>";
704 break;
705
706 case CapDetail::NAMED:
707 str << obj.name();
708 if ( obj.hasArch() )
709 str << archsep << obj.arch();
710 return str;
711 break;
712
713 case CapDetail::VERSIONED:
714 str << obj.name();
715 if ( obj.hasArch() )
716 str << archsep << obj.arch();
717 return str << " " << obj.op() << " " << obj.ed();
718 break;
719
720 case CapDetail::EXPRESSION:
721 {
722 std::string outs;
723 auto pool = sat::Pool::instance().get();
724 auto op = obj.capRel();
725 if ( obj.capRel() == CapDetail::CAP_NAMESPACE ) {
726 cap2strHelper( outs, pool, obj.lhs().id(), op );
727 outs += "(";
728 cap2strHelper( outs, pool, obj.rhs().id(), op );
729 outs += ")";
730 }
731 else {
732 outs += "(";
733 cap2strHelper( outs, pool, obj.lhs().id(), op );
734 outs += opstr( op );
735 cap2strHelper( outs, pool, obj.rhs().id(), op );
736 outs += ")";
737 }
738 return str << outs;
739 }
740 break;
741 }
742 return str << "<UnknownCap(" << obj.lhs() << " " << obj.capRel() << " " << obj.rhs() << ")>";
743 }
744
745 std::ostream & operator<<( std::ostream & str, CapDetail::Kind obj )
746 {
747 switch ( obj )
748 {
749 case CapDetail::NOCAP: return str << "NoCap"; break;
750 case CapDetail::NAMED: return str << "NamedCap"; break;
751 case CapDetail::VERSIONED: return str << "VersionedCap"; break;
752 case CapDetail::EXPRESSION: return str << "CapExpression"; break;
753 }
754 return str << "UnknownCap";
755 }
756
757 std::ostream & operator<<( std::ostream & str, CapDetail::CapRel obj )
758 {
759 if ( obj == CapDetail::REL_NONE )
760 return str << "NoCapRel";
761 return str << static_cast<Capability::CapRel>(obj);
762 }
763
765} // namespace zypp
Arch.h
Capability.h
Edition.h
Exception.h
Gettext.h
LogTools.h
PoolMember.h
Pool.h
Regex.h
Rel.h
ResPool.h
String.h
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::CapDetail
Helper providing more detailed information about a Capability.
Definition Capability.h:365
zypp::CapDetail::CapDetail
CapDetail()
Definition Capability.h:396
zypp::CapDetail::isNamed
bool isNamed() const
Definition Capability.h:409
zypp::CapDetail::Kind
Kind
Definition Capability.h:368
zypp::CapDetail::NAMED
@ NAMED
Definition Capability.h:370
zypp::CapDetail::NOCAP
@ NOCAP
Definition Capability.h:369
zypp::CapDetail::EXPRESSION
@ EXPRESSION
Definition Capability.h:372
zypp::CapDetail::VERSIONED
@ VERSIONED
Definition Capability.h:371
zypp::CapDetail::name
IdString name() const
Definition Capability.h:418
zypp::CapDetail::hasArch
bool hasArch() const
Definition Capability.h:416
zypp::CapDetail::arch
IdString arch() const
Definition Capability.h:417
zypp::CapDetail::rhs
Capability rhs() const
Definition Capability.h:427
zypp::CapDetail::ed
Edition ed() const
Definition Capability.h:420
zypp::CapDetail::op
Rel op() const
Definition Capability.h:419
zypp::CapDetail::_archIfSimple
sat::detail::IdType _archIfSimple
Definition Capability.h:437
zypp::CapDetail::lhs
Capability lhs() const
Definition Capability.h:425
zypp::CapDetail::kind
Kind kind() const
Definition Capability.h:407
zypp::CapDetail::_init
void _init()
Definition Capability.cc:640
zypp::CapDetail::_kind
Kind _kind
Definition Capability.h:433
zypp::CapDetail::_rhs
sat::detail::IdType _rhs
Definition Capability.h:435
zypp::CapDetail::capRel
CapRel capRel() const
Definition Capability.h:426
zypp::CapDetail::_lhs
sat::detail::IdType _lhs
Definition Capability.h:434
zypp::CapDetail::_flag
unsigned _flag
Definition Capability.h:436
zypp::CapDetail::CapRel
CapRel
Enum values corresponding with libsolv defines.
Definition Capability.h:379
zypp::CapDetail::REL_NONE
@ REL_NONE
Not an expression.
Definition Capability.h:380
zypp::CapDetail::CAP_ARCH
@ CAP_ARCH
Used internally.
Definition Capability.h:392
zypp::CapDetail::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition Capability.h:391
zypp::CapMatch
Tri state Capability match result.
Definition CapMatch.h:39
zypp::CapMatch::no
static const CapMatch no
Definition CapMatch.h:53
zypp::CapMatch::irrelevant
static const CapMatch irrelevant
Definition CapMatch.h:54
zypp::CapMatch::yes
static const CapMatch yes
Definition CapMatch.h:52
zypp::Capability
A sat capability.
Definition Capability.h:63
zypp::Capability::id
sat::detail::IdType id() const
Expert backdoor.
Definition Capability.h:288
zypp::Capability::Null
static const Capability Null
No or Null Capability ( Id 0 ).
Definition Capability.h:172
zypp::Capability::_id
sat::detail::IdType _id
Definition Capability.h:294
zypp::Capability::Capability
Capability()
Default ctor, Empty capability.
Definition Capability.h:69
zypp::Capability::empty
bool empty() const
Whether the Capability is empty.
Definition Capability.h:185
zypp::Capability::CapRel
CapRel
Enum values correspond with libsolv defines.
Definition Capability.h:152
zypp::Capability::CAP_OR
@ CAP_OR
or
Definition Capability.h:154
zypp::Capability::CAP_WITH
@ CAP_WITH
with
Definition Capability.h:160
zypp::Capability::CAP_WITHOUT
@ CAP_WITHOUT
without
Definition Capability.h:161
zypp::Capability::CAP_COND
@ CAP_COND
if
Definition Capability.h:156
zypp::Capability::CAP_ELSE
@ CAP_ELSE
else
Definition Capability.h:158
zypp::Capability::CAP_ARCH
@ CAP_ARCH
Used internally.
Definition Capability.h:164
zypp::Capability::CAP_UNLESS
@ CAP_UNLESS
unless
Definition Capability.h:157
zypp::Capability::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition Capability.h:163
zypp::Capability::CAP_AND
@ CAP_AND
and
Definition Capability.h:153
zypp::Capability::detail
CapDetail detail() const
Helper providing more detailed information about a Capability.
Definition Capability.h:452
zypp::Capability::c_str
const char * c_str() const
Conversion to const char *.
Definition Capability.cc:446
zypp::Capability::_doMatch
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
Definition Capability.cc:458
zypp::Capability::isInterestingFileSpec
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
Definition Capability.h:251
zypp::Capability::CtorFlag
CtorFlag
Definition Capability.h:65
zypp::Capability::UNPARSED
@ UNPARSED
Definition Capability.h:65
zypp::Capability::Empty
static const Capability Empty
Empty Capability.
Definition Capability.h:175
zypp::Capability::guessPackageSpec
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing "libzypp-1.2.3-4.5.x86_64" formats.
Definition Capability.cc:572
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:61
zypp::Edition::MatchRange
Range< Edition, Match > MatchRange
Edition Range based on Match.
Definition Edition.h:169
zypp::Edition::noedition
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition Edition.h:73
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *.
Definition IdString.cc:50
zypp::IdString::empty
constexpr bool empty() const
Whether the string is empty.
Definition IdString.h:88
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition IdString.h:133
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::ResPool
Global ResObject pool.
Definition ResPool.h:62
zypp::ResPool::instance
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition Pool.h:55
zypp::sat::Pool::get
detail::CPool * get() const
Expert backdoor.
Definition Pool.cc:49
zypp::sat::Solvable::SplitIdent
Helper that splits an identifier into kind and name or vice versa.
Definition Solvable.h:381
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition WhatProvides.h:89
zypp::sat::WhatProvides::empty
bool empty() const
Whether the container is empty.
Definition WhatProvides.cc:129
zypp::sat::detail::PoolImpl::parserpmrichdep
sat::detail::IdType parserpmrichdep(const char *capstr_r)
libsolv capability parser
Definition PoolImpl.h:191
zypp::str::regex
Regular expression.
Definition Regex.h:95
zypp::str::regex::nosubs
@ nosubs
Support for substring addressing of matches is not required.
Definition Regex.h:100
zypp::str::smatch
Regular expression match result.
Definition Regex.h:168
str
String related utilities and Regular expression matching.
zypp::pool
Definition ByIdent.h:24
zypp::sat::detail::emptyId
static const IdType emptyId(1)
zypp::sat::detail::noId
static const IdType noId(0)
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolMember.h:104
zypp::sat::detail::CPool
::s_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
Definition PoolMember.h:61
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition String.h:290
zypp::str::hasPrefix
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1097
zypp::str::regex_match
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
Definition Regex.h:70
zypp::url::split
void split(ParamVec &pvec, const std::string &pstr, const std::string &psep)
Split into a parameter vector.
Definition UrlUtils.cc:164
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ResolverNamespace
ResolverNamespace
The resolver's dependency namespaces.
Definition ResolverNamespace.h:25
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition Capability.cc:588
zypp::overlaps
bool overlaps(const Range< Tp, TCompare > &lhs, const Range< Tp, TCompare > &rhs)
Definition Range.h:65
zypp::Arch_empty
const Arch Arch_empty(IdString::Empty)
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
PoolImpl.h
zypp::Rel
Relational operators.
Definition Rel.h:46
zypp::Rel::LT
static const Rel LT
Definition Rel.h:54
zypp::Rel::LE
static const Rel LE
Definition Rel.h:55
zypp::Rel::GE
static const Rel GE
Definition Rel.h:57
zypp::Rel::NE
static const Rel NE
Definition Rel.h:53
zypp::Rel::ANY
static const Rel ANY
Definition Rel.h:58
zypp::Rel::EQ
static const Rel EQ
Definition Rel.h:52
zypp::Rel::isRel
static bool isRel(unsigned bits_r)
Test whether bits_r is a valid Rel (no extra bits set).
Definition Rel.h:113
zypp::dumpCap::_cap
Capability _cap
Definition Capability.h:340
zypp::dumpCap::_dumpRec
std::ostream & _dumpRec(std::ostream &str, Capability cap_r, std::string lvl_r="") const
Definition Capability.cc:612
zypp::dumpCap::dumpOn
std::ostream & dumpOn(std::ostream &str) const
Definition Capability.cc:610
zypp::sat::detail::PoolMember::myPool
static PoolImpl & myPool()
Definition PoolImpl.cc:185