Imported Upstream version 17.9.0
[platform/upstream/libzypp.git] / zypp / sat / Solvable.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Solvable.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/Exception.h"
17 #include "zypp/base/Functional.h"
18 #include "zypp/base/Collector.h"
19 #include "zypp/base/Xml.h"
20
21 #include "zypp/sat/detail/PoolImpl.h"
22 #include "zypp/sat/Solvable.h"
23 #include "zypp/sat/Pool.h"
24 #include "zypp/sat/LookupAttr.h"
25
26 #include "zypp/Repository.h"
27 #include "zypp/OnMediaLocation.h"
28 #include "zypp/ZConfig.h"
29
30 #include "zypp/ui/Selectable.h"
31
32 using std::endl;
33
34 ///////////////////////////////////////////////////////////////////
35 namespace zypp
36 {
37   ///////////////////////////////////////////////////////////////////
38   namespace sat
39   {
40     ///////////////////////////////////////////////////////////////////
41     namespace
42     {
43       void _doSplit( IdString & _ident, ResKind & _kind, IdString & _name )
44       {
45         if ( ! _ident )
46           return;
47
48         ResKind explicitKind = ResKind::explicitBuiltin( _ident.c_str() );
49         // NOTE: kind package and srcpackage do not have namespaced ident!
50         if ( ! explicitKind  )
51         {
52           _name = _ident;
53           // No kind defaults to package
54           if ( !_kind )
55             _kind = ResKind::package;
56           else if ( ! ( _kind == ResKind::package || _kind == ResKind::srcpackage ) )
57             _ident = IdString( str::form( "%s:%s", _kind.c_str(), _ident.c_str() ) );
58         }
59         else
60         {
61           // strip kind spec from name
62           _name = IdString( ::strchr( _ident.c_str(), ':' )+1 );
63           _kind = explicitKind;
64           if ( _kind == ResKind::package || _kind == ResKind::srcpackage )
65             _ident = _name;
66         }
67         return;
68       }
69     } // namespace
70     ///////////////////////////////////////////////////////////////////
71
72     Solvable::SplitIdent::SplitIdent( IdString ident_r )
73     : _ident( ident_r )
74     { _doSplit( _ident, _kind, _name ); }
75
76     Solvable::SplitIdent::SplitIdent( const char * ident_r )
77     : _ident( ident_r )
78     { _doSplit( _ident, _kind, _name ); }
79
80     Solvable::SplitIdent::SplitIdent( const std::string & ident_r )
81     : _ident( ident_r )
82     { _doSplit( _ident, _kind, _name ); }
83
84     Solvable::SplitIdent::SplitIdent( ResKind kind_r, IdString name_r )
85     : _ident( name_r )
86     , _kind( kind_r )
87     { _doSplit( _ident, _kind, _name ); }
88
89     Solvable::SplitIdent::SplitIdent( ResKind kind_r, const C_Str & name_r )
90     : _ident( name_r )
91     , _kind( kind_r )
92     { _doSplit( _ident, _kind, _name ); }
93
94     /////////////////////////////////////////////////////////////////
95     //  class Solvable
96     /////////////////////////////////////////////////////////////////
97
98     const Solvable Solvable::noSolvable;
99
100     /////////////////////////////////////////////////////////////////
101
102     detail::CSolvable * Solvable::get() const
103     { return myPool().getSolvable( _id ); }
104
105 #define NO_SOLVABLE_RETURN( VAL ) \
106     detail::CSolvable * _solvable( get() ); \
107     if ( ! _solvable ) return VAL
108
109     Solvable Solvable::nextInPool() const
110     { return Solvable( myPool().getNextId( _id ) ); }
111
112     Solvable Solvable::nextInRepo() const
113     {
114       NO_SOLVABLE_RETURN( noSolvable );
115       for ( detail::SolvableIdType next = _id+1; next < unsigned(_solvable->repo->end); ++next )
116       {
117         detail::CSolvable * nextS( myPool().getSolvable( next ) );
118         if ( nextS && nextS->repo == _solvable->repo )
119         {
120           return Solvable( next );
121         }
122       }
123       return noSolvable;
124     }
125
126     std::string Solvable::lookupStrAttribute( const SolvAttr & attr ) const
127     {
128       NO_SOLVABLE_RETURN( std::string() );
129       const char * s = ::solvable_lookup_str( _solvable, attr.id() );
130       return s ? s : std::string();
131     }
132
133     std::string Solvable::lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const
134     {
135       NO_SOLVABLE_RETURN( std::string() );
136       const char * s = 0;
137       if ( !lang_r )
138       {
139         s = ::solvable_lookup_str_poollang( _solvable, attr.id() );
140       }
141       else
142       {
143         for ( Locale l( lang_r ); l; l = l.fallback() )
144         {
145           if ( (s = ::solvable_lookup_str_lang( _solvable, attr.id(), l.c_str(), 0 )) )
146             return s;
147         }
148         // here: no matching locale, so use default
149         s = ::solvable_lookup_str_lang( _solvable, attr.id(), 0, 0 );
150       }
151       return s ? s : std::string();
152    }
153
154     unsigned long long Solvable::lookupNumAttribute( const SolvAttr & attr ) const
155     {
156       NO_SOLVABLE_RETURN( 0 );
157       return ::solvable_lookup_num( _solvable, attr.id(), 0 );
158     }
159
160     unsigned long long Solvable::lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const
161     {
162       NO_SOLVABLE_RETURN( notfound_r );
163       return ::solvable_lookup_num( _solvable, attr.id(), notfound_r );
164     }
165
166     bool Solvable::lookupBoolAttribute( const SolvAttr & attr ) const
167     {
168       NO_SOLVABLE_RETURN( false );
169       return ::solvable_lookup_bool( _solvable, attr.id() );
170     }
171
172     detail::IdType Solvable::lookupIdAttribute( const SolvAttr & attr ) const
173     {
174       NO_SOLVABLE_RETURN( detail::noId );
175       return ::solvable_lookup_id( _solvable, attr.id() );
176     }
177
178     CheckSum Solvable::lookupCheckSumAttribute( const SolvAttr & attr ) const
179     {
180       NO_SOLVABLE_RETURN( CheckSum() );
181       detail::IdType chksumtype = 0;
182       const char * s = ::solvable_lookup_checksum( _solvable, attr.id(), &chksumtype );
183       if ( ! s )
184         return CheckSum();
185       switch ( chksumtype )
186       {
187         case REPOKEY_TYPE_MD5:    return CheckSum::md5( s );
188         case REPOKEY_TYPE_SHA1:   return CheckSum::sha1( s );
189         case REPOKEY_TYPE_SHA224: return CheckSum::sha224( s );
190         case REPOKEY_TYPE_SHA256: return CheckSum::sha256( s );
191         case REPOKEY_TYPE_SHA384: return CheckSum::sha384( s );
192         case REPOKEY_TYPE_SHA512: return CheckSum::sha512( s );
193       }
194       return CheckSum( std::string(), s ); // try to autodetect
195     }
196
197     ///////////////////////////////////////////////////////////////////
198     namespace
199     {
200       inline Pathname lookupDatadirIn( Repository repor_r )
201       {
202         static const SolvAttr susetagsDatadir( "susetags:datadir" );
203         Pathname ret;
204         // First look for repo attribute "susetags:datadir". If not found,
205         // look into the solvables as Code11 libsolv placed it there.
206         LookupRepoAttr datadir( susetagsDatadir, repor_r );
207         if ( ! datadir.empty() )
208           ret = datadir.begin().asString();
209         else
210         {
211           LookupAttr datadir( susetagsDatadir, repor_r );
212           if ( ! datadir.empty() )
213             ret = datadir.begin().asString();
214         }
215         return ret;
216       }
217     } // namespace
218     ///////////////////////////////////////////////////////////////////
219
220     OnMediaLocation Solvable::lookupLocation() const
221     {
222       NO_SOLVABLE_RETURN( OnMediaLocation() );
223       // medianumber and path
224       unsigned medianr;
225       const char * file = ::solvable_lookup_location( _solvable, &medianr );
226       if ( ! file )
227         return OnMediaLocation();
228       if ( ! medianr )
229         medianr = 1;
230
231       OnMediaLocation ret;
232
233       Pathname path;
234       switch ( repository().info().type().toEnum() )
235       {
236         case repo::RepoType::NONE_e:
237         {
238           path = lookupDatadirIn( repository() );
239           if ( ! path.empty() )
240             repository().info().setProbedType( repo::RepoType::YAST2_e );
241         }
242         break;
243
244         case repo::RepoType::YAST2_e:
245         {
246           path = lookupDatadirIn( repository() );
247           if ( path.empty() )
248             path = "suse";
249         }
250         break;
251
252         default:
253           break;
254       }
255       ret.setLocation    ( path/file, medianr );
256       ret.setDownloadSize( ByteCount( lookupNumAttribute( SolvAttr::downloadsize ) ) );
257       ret.setChecksum    ( lookupCheckSumAttribute( SolvAttr::checksum ) );
258       // Not needed/available for solvables?
259       //ret.setOpenSize    ( ByteCount( lookupNumAttribute( SolvAttr::opensize ) ) );
260       //ret.setOpenChecksum( lookupCheckSumAttribute( SolvAttr::openchecksum ) );
261       return ret;
262     }
263
264
265     IdString Solvable::ident() const
266     {
267       NO_SOLVABLE_RETURN( IdString() );
268       return IdString( _solvable->name );
269     }
270
271      ResKind Solvable::kind() const
272     {
273       NO_SOLVABLE_RETURN( ResKind() );
274       // detect srcpackages by 'arch'
275       switch ( _solvable->arch )
276       {
277         case ARCH_SRC:
278         case ARCH_NOSRC:
279           return ResKind::srcpackage;
280           break;
281       }
282
283       // either explicitly prefixed...
284       const char * ident = IdString( _solvable->name ).c_str();
285       ResKind knownKind( ResKind::explicitBuiltin( ident ) );
286       if ( knownKind )
287         return knownKind;
288
289       // ...or no ':' in package names (hopefully)...
290       const char * sep = ::strchr( ident, ':' );
291       if ( ! sep )
292         return ResKind::package;
293
294       // ...or something unknown.
295       return ResKind( std::string( ident, sep-ident ) );
296     }
297
298     bool Solvable::isKind( const ResKind & kind_r ) const
299     {
300       NO_SOLVABLE_RETURN( false );
301
302       // detect srcpackages by 'arch'
303       switch ( _solvable->arch )
304       {
305         case ARCH_SRC:
306         case ARCH_NOSRC:
307           return( kind_r == ResKind::srcpackage );
308           break;
309       }
310
311       // no ':' in package names (hopefully)
312       const char * ident = IdString( _solvable->name ).c_str();
313       if ( kind_r == ResKind::package )
314       {
315         return( ::strchr( ident, ':' ) == 0 );
316       }
317
318       // look for a 'kind:' prefix
319       const char * kind = kind_r.c_str();
320       unsigned     ksize = ::strlen( kind );
321       return( ::strncmp( ident, kind, ksize ) == 0
322               && ident[ksize] == ':' );
323     }
324
325     std::string Solvable::name() const
326     {
327       NO_SOLVABLE_RETURN( std::string() );
328       const char * ident = IdString( _solvable->name ).c_str();
329       const char * sep = ::strchr( ident, ':' );
330       return( sep ? sep+1 : ident );
331     }
332
333     Edition Solvable::edition() const
334     {
335       NO_SOLVABLE_RETURN( Edition() );
336       return Edition( _solvable->evr );
337     }
338
339     Arch Solvable::arch() const
340     {
341       NO_SOLVABLE_RETURN( Arch_noarch ); //ArchId() );
342       switch ( _solvable->arch )
343       {
344         case ARCH_SRC:
345         case ARCH_NOSRC:
346           return Arch_noarch; //ArchId( ARCH_NOARCH );
347           break;
348       }
349       return Arch( IdString(_solvable->arch).asString() );
350       //return ArchId( _solvable->arch );
351     }
352
353     IdString Solvable::vendor() const
354     {
355       NO_SOLVABLE_RETURN( IdString() );
356       return IdString( _solvable->vendor );
357     }
358
359    Repository Solvable::repository() const
360     {
361       NO_SOLVABLE_RETURN( Repository::noRepository );
362       return Repository( _solvable->repo );
363     }
364
365     RepoInfo Solvable::repoInfo() const
366     { return repository().info(); }
367
368
369     bool Solvable::isSystem() const
370     {
371       NO_SOLVABLE_RETURN( _id == detail::systemSolvableId );
372       return myPool().isSystemRepo( _solvable->repo );
373     }
374
375     bool Solvable::onSystemByUser() const
376     {
377       return isSystem() && myPool().isOnSystemByUser( ident() );
378     }
379
380     bool Solvable::onSystemByAuto() const
381     {
382       return isSystem() && myPool().isOnSystemByAuto( ident() );
383     }
384
385     bool Solvable::identIsAutoInstalled( const IdString & ident_r )
386     {
387       return myPool().isOnSystemByAuto( ident_r );
388     }
389
390     bool Solvable::identTriggersRebootNeededHint ( const IdString &ident_r )
391     {
392       return myPool().triggersRebootNeededHint( ident_r );
393     }
394
395     bool Solvable::multiversionInstall() const
396     {
397       NO_SOLVABLE_RETURN( false );
398       return myPool().isMultiversion( *this );
399     }
400
401     Date Solvable::buildtime() const
402     {
403       NO_SOLVABLE_RETURN( Date() );
404       return Date( lookupNumAttribute( SolvAttr::buildtime ) );
405     }
406
407     Date Solvable::installtime() const
408     {
409       NO_SOLVABLE_RETURN( Date() );
410       return Date( lookupNumAttribute( SolvAttr::installtime ) );
411     }
412
413     std::string Solvable::asString() const
414     {
415       NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
416       return str::form( "%s-%s.%s",
417                         IdString( _solvable->name ).c_str(),
418                         IdString( _solvable->evr ).c_str(),
419                         IdString( _solvable->arch ).c_str() );
420     }
421
422     std::string Solvable::asUserString() const\
423     {
424       NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
425       return str::form( "%s-%s.%s (%s)",
426                         IdString( _solvable->name ).c_str(),
427                         IdString( _solvable->evr ).c_str(),
428                         IdString( _solvable->arch ).c_str(),
429                         repository().asUserString().c_str() );
430     }
431
432     bool Solvable::identical( const Solvable & rhs ) const
433     {
434       NO_SOLVABLE_RETURN( ! rhs.get() );
435       detail::CSolvable * rhssolvable( rhs.get() );
436       return rhssolvable && ( _solvable == rhssolvable || ::solvable_identical( _solvable, rhssolvable ) );
437     }
438
439     ///////////////////////////////////////////////////////////////////
440     namespace
441     {
442       inline Capabilities _getCapabilities( detail::IdType * idarraydata_r, ::Offset offs_r )
443       {
444         return offs_r ? Capabilities( idarraydata_r + offs_r ) : Capabilities();
445       }
446     } // namespace
447     ///////////////////////////////////////////////////////////////////
448
449     Capabilities Solvable::provides() const
450     {
451       NO_SOLVABLE_RETURN( Capabilities() );
452       return _getCapabilities( _solvable->repo->idarraydata, _solvable->provides );
453     }
454     Capabilities Solvable::requires() const
455     {
456       NO_SOLVABLE_RETURN( Capabilities() );
457       return _getCapabilities( _solvable->repo->idarraydata, _solvable->requires );
458     }
459     Capabilities Solvable::conflicts() const
460     {
461       NO_SOLVABLE_RETURN( Capabilities() );
462       return _getCapabilities( _solvable->repo->idarraydata, _solvable->conflicts );
463     }
464     Capabilities Solvable::obsoletes() const
465     {
466       NO_SOLVABLE_RETURN( Capabilities() );
467       return _getCapabilities( _solvable->repo->idarraydata, _solvable->obsoletes );
468     }
469     Capabilities Solvable::recommends() const
470     {
471       NO_SOLVABLE_RETURN( Capabilities() );
472       return _getCapabilities( _solvable->repo->idarraydata, _solvable->recommends );
473     }
474     Capabilities Solvable::suggests() const
475     {
476       NO_SOLVABLE_RETURN( Capabilities() );
477       return _getCapabilities( _solvable->repo->idarraydata, _solvable->suggests );
478     }
479     Capabilities Solvable::enhances() const
480     {
481       NO_SOLVABLE_RETURN( Capabilities() );
482       return _getCapabilities( _solvable->repo->idarraydata, _solvable->enhances );
483     }
484     Capabilities Solvable::supplements() const
485     {
486       NO_SOLVABLE_RETURN( Capabilities() );
487       return _getCapabilities( _solvable->repo->idarraydata, _solvable->supplements );
488     }
489     Capabilities Solvable::prerequires() const
490     {
491       NO_SOLVABLE_RETURN( Capabilities() );
492       // prerequires are a subset of requires
493        ::Offset offs = _solvable->requires;
494        return offs ? Capabilities( _solvable->repo->idarraydata + offs, detail::solvablePrereqMarker )
495                    : Capabilities();
496     }
497
498     CapabilitySet Solvable::providesNamespace( const std::string & namespace_r ) const
499     {
500       NO_SOLVABLE_RETURN( CapabilitySet() );
501       CapabilitySet ret;
502       Capabilities caps( provides() );
503       for_( it, caps.begin(), caps.end() )
504       {
505         CapDetail caprep( it->detail() );
506         if ( str::hasPrefix( caprep.name().c_str(), namespace_r ) && *(caprep.name().c_str()+namespace_r.size()) == '(' )
507           ret.insert( *it );
508       }
509       return ret;
510     }
511
512     CapabilitySet Solvable::valuesOfNamespace( const std::string & namespace_r ) const
513     {
514       NO_SOLVABLE_RETURN( CapabilitySet() );
515       CapabilitySet ret;
516       Capabilities caps( provides() );
517       for_( it, caps.begin(), caps.end() )
518       {
519         CapDetail caprep( it->detail() );
520         if ( str::hasPrefix( caprep.name().c_str(), namespace_r ) && *(caprep.name().c_str()+namespace_r.size()) == '(' )
521         {
522           std::string value( caprep.name().c_str()+namespace_r.size()+1 );
523           value[value.size()-1] = '\0'; // erase the trailing ')'
524           ret.insert( Capability( value, caprep.op(), caprep.ed() ) );
525         }
526       }
527       return ret;
528     }
529
530     ///////////////////////////////////////////////////////////////////
531     namespace
532     {
533       /** Expand \ref Capability and call \c fnc_r for each namespace:language
534        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
535        * false to indicate abort.
536        */
537       int invokeOnEachSupportedLocale( Capability cap_r, function<bool (const Locale &)> fnc_r )
538       {
539         CapDetail detail( cap_r );
540         if ( detail.kind() == CapDetail::EXPRESSION )
541         {
542           switch ( detail.capRel() )
543           {
544             case CapDetail::CAP_AND:
545             case CapDetail::CAP_OR:
546                 // expand
547               {
548                 int res = invokeOnEachSupportedLocale( detail.lhs(), fnc_r );
549                 if ( res < 0 )
550                   return res; // negative on abort.
551                 int res2 = invokeOnEachSupportedLocale( detail.rhs(), fnc_r );
552                 if ( res2 < 0 )
553                   return -res + res2; // negative on abort.
554                 return res + res2;
555               }
556               break;
557
558             case CapDetail::CAP_NAMESPACE:
559               if ( detail.lhs().id() == NAMESPACE_LANGUAGE )
560               {
561                 return ( !fnc_r || fnc_r( Locale( IdString(detail.rhs().id()) ) ) ) ? 1 : -1; // negative on abort.
562               }
563               break;
564
565             case CapDetail::REL_NONE:
566             case CapDetail::CAP_WITH:
567             case CapDetail::CAP_ARCH:
568               break; // unwanted
569           }
570         }
571         return 0;
572       }
573
574        /** Expand \ref Capability and call \c fnc_r for each namespace:language
575        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
576        * false to indicate abort.
577        */
578       inline int invokeOnEachSupportedLocale( Capabilities cap_r, function<bool (Locale)> fnc_r )
579       {
580         int cnt = 0;
581         for_( cit, cap_r.begin(), cap_r.end() )
582         {
583           int res = invokeOnEachSupportedLocale( *cit, fnc_r );
584           if ( res < 0 )
585             return -cnt + res; // negative on abort.
586           cnt += res;
587         }
588         return cnt;
589       }
590       //@}
591
592       // Functor returning false if a Locale is in the set.
593       struct NoMatchIn
594       {
595         NoMatchIn( const LocaleSet & locales_r ) : _locales( locales_r ) {}
596
597         bool operator()( const Locale & locale_r ) const
598         {
599           return _locales.find( locale_r ) == _locales.end();
600         }
601
602         const LocaleSet & _locales;
603       };
604     } // namespace
605     ///////////////////////////////////////////////////////////////////
606
607     bool Solvable::supportsLocales() const
608     {
609       // false_c stops on 1st Locale.
610       return invokeOnEachSupportedLocale( supplements(), functor::false_c() ) < 0;
611     }
612
613     bool Solvable::supportsLocale( const Locale & locale_r ) const
614     {
615       // not_equal_to stops on == Locale.
616       return invokeOnEachSupportedLocale( supplements(), bind( std::not_equal_to<Locale>(), locale_r, _1 ) ) < 0;
617     }
618
619     bool Solvable::supportsLocale( const LocaleSet & locales_r ) const
620     {
621       if ( locales_r.empty() )
622         return false;
623       // NoMatchIn stops if Locale is included.
624       return invokeOnEachSupportedLocale( supplements(), NoMatchIn(locales_r) ) < 0;
625     }
626
627     bool Solvable::supportsRequestedLocales() const
628     { return supportsLocale( myPool().getRequestedLocales() ); }
629
630     LocaleSet Solvable::getSupportedLocales() const
631     {
632       LocaleSet ret;
633       invokeOnEachSupportedLocale( supplements(), functor::collector( std::inserter( ret, ret.begin() ) ) );
634       return ret;
635     }
636
637     CpeId Solvable::cpeId() const
638     {
639       NO_SOLVABLE_RETURN( CpeId() );
640       return CpeId( lookupStrAttribute( SolvAttr::cpeid ), CpeId::noThrow );
641     }
642
643     unsigned Solvable::mediaNr() const
644     {
645       NO_SOLVABLE_RETURN( 0U );
646       // medianumber and path
647       unsigned medianr = 0U;
648       const char * file = ::solvable_lookup_location( _solvable, &medianr );
649       if ( ! file )
650         medianr = 0U;
651       else if ( ! medianr )
652         medianr = 1U;
653       return medianr;
654     }
655
656     ByteCount Solvable::installSize() const
657     {
658       NO_SOLVABLE_RETURN( ByteCount() );
659       return ByteCount( lookupNumAttribute( SolvAttr::installsize ) );
660     }
661
662     ByteCount Solvable::downloadSize() const
663     {
664       NO_SOLVABLE_RETURN( ByteCount() );
665       return ByteCount( lookupNumAttribute( SolvAttr::downloadsize ) );
666     }
667
668     std::string Solvable::distribution() const
669     {
670       NO_SOLVABLE_RETURN( std::string() );
671       return lookupStrAttribute( SolvAttr::distribution );
672     }
673
674     std::string Solvable::summary( const Locale & lang_r ) const
675     {
676       NO_SOLVABLE_RETURN( std::string() );
677       return lookupStrAttribute( SolvAttr::summary, lang_r );
678     }
679
680     std::string Solvable::description( const Locale & lang_r ) const
681     {
682       NO_SOLVABLE_RETURN( std::string() );
683       return lookupStrAttribute( SolvAttr::description, lang_r );
684     }
685
686     std::string Solvable::insnotify( const Locale & lang_r ) const
687     {
688       NO_SOLVABLE_RETURN( std::string() );
689       return lookupStrAttribute( SolvAttr::insnotify, lang_r );
690     }
691
692     std::string Solvable::delnotify( const Locale & lang_r ) const
693     {
694       NO_SOLVABLE_RETURN( std::string() );
695       return lookupStrAttribute( SolvAttr::delnotify, lang_r );
696     }
697
698     std::string Solvable::licenseToConfirm( const Locale & lang_r ) const
699     {
700       NO_SOLVABLE_RETURN( std::string() );
701       std::string ret = lookupStrAttribute( SolvAttr::eula, lang_r );
702       if ( ret.empty() && isKind<Product>() )
703       {
704         const RepoInfo & ri( repoInfo() );
705         std::string riname( name() );   // "license-"+name with fallback "license"
706         if ( ! ri.hasLicense( riname ) )
707           riname.clear();
708
709         if ( ri.needToAcceptLicense( riname ) || ! ui::Selectable::get( *this )->hasInstalledObj() )
710           ret = ri.getLicense( riname, lang_r ); // bnc#908976: suppress informal license upon update
711       }
712       return ret;
713     }
714
715     bool Solvable::needToAcceptLicense() const
716     {
717       NO_SOLVABLE_RETURN( false );
718       if ( isKind<Product>() )
719       {
720         const RepoInfo & ri( repoInfo() );
721         std::string riname( name() );   // "license-"+name with fallback "license"
722         if ( ! ri.hasLicense( riname ) )
723           riname.clear();
724
725         return ri.needToAcceptLicense( riname );
726       }
727       return true;
728     }
729
730
731     std::ostream & operator<<( std::ostream & str, const Solvable & obj )
732     {
733       if ( ! obj )
734         return str << (obj.isSystem() ? "systemSolvable" : "noSolvable" );
735
736       return str << "(" << obj.id() << ")"
737           << ( obj.isKind( ResKind::srcpackage ) ? "srcpackage:" : "" ) << obj.ident()
738           << '-' << obj.edition() << '.' << obj.arch() << "("
739           << obj.repository().alias() << ")";
740     }
741
742     std::ostream & dumpOn( std::ostream & str, const Solvable & obj )
743     {
744       str << obj;
745       if ( obj )
746       {
747 #define OUTS(X) if ( ! obj[Dep::X].empty() ) str << endl << " " #X " " << obj[Dep::X]
748         OUTS(PROVIDES);
749         OUTS(PREREQUIRES);
750         OUTS(REQUIRES);
751         OUTS(CONFLICTS);
752         OUTS(OBSOLETES);
753         OUTS(RECOMMENDS);
754         OUTS(SUGGESTS);
755         OUTS(ENHANCES);
756         OUTS(SUPPLEMENTS);
757 #undef OUTS
758       }
759       return str;
760     }
761
762     std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj )
763     {
764       xmlout::Node guard( str, "solvable" );
765
766       dumpAsXmlOn( *guard, obj.kind() );
767       *xmlout::Node( *guard, "name" ) << obj.name();
768       dumpAsXmlOn( *guard, obj.edition() );
769       dumpAsXmlOn( *guard, obj.arch() );
770       dumpAsXmlOn( *guard, obj.repository() );
771       return str;
772     }
773
774   } // namespace sat
775   ///////////////////////////////////////////////////////////////////
776 } // namespace zypp
777 ///////////////////////////////////////////////////////////////////