libzypp  17.36.7
Package.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 
15 #include <zypp/base/LogTools.h>
16 #include <zypp/base/String.h>
17 #include <zypp/base/StringV.h>
18 #include <zypp/Package.h>
19 #include <zypp/sat/LookupAttr.h>
20 #include <zypp/ZYppFactory.h>
21 #include <zypp/target/rpm/RpmDb.h>
23 #include <zypp/ui/Selectable.h>
24 
26 namespace zyppintern
27 {
28  using namespace zypp;
29 
31  using GetVendorSupportOptionReturn = std::pair<VendorSupportOption,std::optional<std::set<std::string_view>>>;
32 
35  {
36  static const IdString support_unsupported( "support_unsupported" );
37  static const IdString support_acc( "support_acc" );
38  static const IdString support_l1( "support_l1" );
39  static const IdString support_l2( "support_l2" );
40  static const IdString support_l3( "support_l3" );
41  static const IdString support_superseded( "support_superseded" ); // opt. followed by "(PKGNAME)"
42 
44 
45  // max over all identical packages
46  for ( const auto & solv : sat::WhatProvides( (Capability(solv_r.ident().id())) ) )
47  {
48  if ( solv.edition() == solv_r.edition()
49  && solv.ident() == solv_r.ident()
50  && solv_r.identical( solv ) )
51  {
53  {
54  switch ( ret.first )
55  {
57  if ( kw == support_unsupported ) { ret.first = VendorSupportUnsupported; break; }
59  if ( kw == support_acc ) { ret.first = VendorSupportACC; break; }
60  case VendorSupportACC:
61  if ( kw == support_l1 ) { ret.first = VendorSupportLevel1; break; }
63  if ( kw == support_l2 ) { ret.first = VendorSupportLevel2; break; }
65  if ( kw == support_l3 ) { ret.first = VendorSupportLevel3; break; }
68  // VendorSupportSuperseded is special as the kw may also contain a '(PKGNAME)'.
69  // In fact even multiple (PKGNAMES) derived from multiple keywords.
70  if ( strv::hasPrefix( kw.asStringView(), support_superseded.asStringView() ) ) {
71  ret.first = VendorSupportSuperseded;
72  if ( kw.c_str()[support_superseded.size()] == '(' && kw.c_str()[kw.size()-1] == ')' ) {
73  std::string_view val { kw.c_str()+support_superseded.size()+1, kw.size()-support_superseded.size()-2 };
74  if ( not val.empty() ) {
75  if ( not ret.second )
76  ret.second = std::set<std::string_view>();
77  ret.second->insert( val );
78  } else {
79  WAR << "No superseding package defined in " << kw << endl;
80  }
81  } else {
82  WAR << "No superseding package defined in " << kw << endl;
83  }
84  }
85  }
86  }
87  }
88  }
89  return ret;
90  }
91 
92  inline bool schemeIsLocalDir( const Url & url_r )
93  {
94  const std::string & s( url_r.getScheme() );
95  return s == "dir" || s == "file";
96  }
97 
98  // here and from SrcPackage.cc
99  Pathname cachedLocation( const OnMediaLocation & loc_r, const RepoInfo & repo_r )
100  {
101  PathInfo pi( repo_r.packagesPath() / repo_r.path() / loc_r.filename() );
102 
103  if ( ! pi.isExist() )
104  return Pathname(); // no file in cache
105 
106  if ( loc_r.checksum().empty() )
107  {
108  Url url( repo_r.url() );
109  if ( ! schemeIsLocalDir( url ) )
110  return Pathname(); // same name but no checksum to verify
111 
112  // for local repos compare with the checksum in repo
113  if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / repo_r.path() / loc_r.filename()).c_str() ) )
114  != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
115  return Pathname(); // same name but wrong checksum
116  }
117  else
118  {
119  if ( loc_r.checksum() != CheckSum( loc_r.checksum().type(), std::ifstream( pi.c_str() ) ) )
120  return Pathname(); // same name but wrong checksum
121  }
122 
123  return pi.path(); // the right one
124  }
125 } // namespace zyppintern
127 
129 namespace zypp
130 {
131 
133 
135  //
136  // METHOD NAME : Package::Package
137  // METHOD TYPE : Ctor
138  //
139  Package::Package( const sat::Solvable & solvable_r )
140  : ResObject( solvable_r )
141  {}
142 
144  //
145  // METHOD NAME : Package::~Package
146  // METHOD TYPE : Dtor
147  //
149  {}
150 
152  { return zyppintern::getVendorSupportOption( satSolvable() ).first; }
153 
155  {
156  switch ( vendorSupport() )
157  {
160  case VendorSupportACC:
162  return true;
163 
164  case VendorSupportLevel1:
165  case VendorSupportLevel2:
166  case VendorSupportLevel3:
167  break; // intentionally no default:
168  }
169  return false;
170  }
171 
172  std::vector<std::string> Package::supersededBy() const
173  {
174  std::vector<std::string> ret;
175  const auto & res = zyppintern::getVendorSupportOption( satSolvable() );
176  if ( res.second ) {
177  // translate the string_view set into stings
178  for ( const auto & v : *res.second )
179  ret.push_back( std::string( v ) );
180  }
181  return ret;
182  }
183 
184 
185  std::pair<std::vector<IdString>,std::vector<std::string>> Package::supersededByItems() const
186  {
187  std::pair<std::vector<IdString>,std::vector<std::string>> ret;
188  std::vector<std::string> todo { supersededBy() };
189  if ( not todo.empty() )
190  {
191  std::set<std::string> done; // taken from todo and processed
192  std::set<std::string> unresolved; // supersededBy does not name a package
193  std::set<IdString> resolved; // supersededBy resolved to package (not superseded)
194  while ( not todo.empty() ) {
195  auto doneit { done.insert( std::move(todo.back()) ) };
196  todo.pop_back();
197  if ( not doneit.second )
198  continue; // already processed
199  const std::string & next { *doneit.first };
200 
201  if ( auto sel = ui::Selectable::get( next ) ) {
202  const std::vector<std::string> & more { sel->supersededBy() };
203  if ( more.empty() ) {
204  resolved.insert( sel->ident() );
205  } else {
206  todo.insert( todo.end(), more.begin(), more.end() );
207  }
208  } else {
209  unresolved.insert( next );
210  }
211  }
212  if ( not resolved.empty() )
213  ret.first.insert( ret.first.end(), resolved.begin(), resolved.end() );
214  if ( not unresolved.empty() )
215  ret.second.insert( ret.second.end(), unresolved.begin(), unresolved.end() );
216  }
217  return ret;
218  }
219 
221  {
222  Target_Ptr target( getZYpp()->getTarget() );
223  if ( ! target )
224  {
225  ERR << "Target not initialized. Changelog is not available." << std::endl;
226  return Changelog();
227  }
228 
229  if ( repository().isSystemRepo() )
230  {
232  target->rpmDb().getData(name(), header);
233  return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
234  }
235  WAR << "changelog is not available for uninstalled packages" << std::endl;
236  return Changelog();
237  }
238 
239  std::string Package::buildhost() const
241 
242  std::string Package::distribution() const
244 
245  std::string Package::license() const
247 
248  std::string Package::packager() const
250 
251  std::string Package::group() const
253 
256 
257  std::string Package::url() const
259 
262 
263  std::list<std::string> Package::authors() const
264  {
265  std::list<std::string> ret;
266  str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
267  return ret;
268  }
269 
272 
275 
277  { return lookupLocation(); }
278 
280  { return zyppintern::cachedLocation( location(), repoInfo() ); }
281 
282  std::string Package::sourcePkgName() const
283  {
284  // no id means same as package
286  return id ? IdString( id ).asString() : name();
287  }
288 
290  {
291  // no id means same as package
293  return id ? Edition( id ) : edition();
294  }
295 
296  std::string Package::sourcePkgType() const
298 
299  std::string Package::sourcePkgLongName() const
300  { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
301 
302 
304 } // namespace zypp
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:551
Package keywords.
Pathname path() const
Repository path.
Definition: RepoInfo.cc:657
std::string distribution() const
Definition: Package.cc:242
Package(const sat::Solvable &solvable_r)
Ctor.
Definition: Package.cc:139
A Solvable object within the sat Pool.
Definition: Solvable.h:53
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
#define IMPL_PTR_TYPE(NAME)
The package was discontinued and has been superseded by a new package with a different name...
Pathname cachedLocation(const OnMediaLocation &loc_r, const RepoInfo &repo_r)
Definition: Package.cc:99
bool schemeIsLocalDir(const Url &url_r)
Definition: Package.cc:92
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
Describes a resource file located on a medium.
Problem isolation, which means technical support designed to duplicate customer problems, isolate problem area and provide resolution for problems not resolved by Level 1 Support.
Store and operate with byte count.
Definition: ByteCount.h:31
ByteCount sourcesize() const
Size of corresponding the source package.
Definition: Package.cc:260
std::string url() const
Don&#39;t ship it as class Url, because it might be in fact anything but a legal Url. ...
Definition: Package.cc:257
IdType id() const
Expert backdoor.
Definition: IdString.h:133
std::list< ChangelogEntry > Changelog
List of ChangelogEntry.
Definition: Changelog.h:55
Pathname cachedLocation() const
Location of the downloaded package in cache or an empty path.
Definition: Package.cc:279
std::string sourcePkgType() const
The type of the source rpm ("src" or "nosrc").
Definition: Package.cc:296
The support for this package is unknown.
std::vector< std::string > supersededBy() const
The name(s) of the successor package if vendorSupport is VendorSupportSuperseded. ...
Definition: Package.cc:172
int IdType
Generic Id type.
Definition: PoolMember.h:104
What is known about a repository.
Definition: RepoInfo.h:71
OnMediaLocation location() const
Location of the resolvable in the repository.
Definition: Package.cc:276
static const SolvAttr packager
Definition: SolvAttr.h:113
Problem resolution, which means technical support designed to resolve complex problems by engaging en...
Access to the sat-pools string space.
Definition: IdString.h:43
Problem determination, which means technical support designed to provide compatibility information...
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
LookupAttr::TransformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:599
GetVendorSupportOptionReturn getVendorSupportOption(sat::Solvable solv_r)
Get VendorSupportOption and the PKGNAME if VendorSupportSuperseded.
Definition: Package.cc:34
static const SolvAttr sourcearch
Definition: SolvAttr.h:119
const CheckSum & checksum() const
The checksum of the resource on the server.
Changelog changelog() const
Get the package change log.
Definition: Package.cc:220
CheckSum lookupCheckSumAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:159
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
bool identical(const Solvable &rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:468
std::string buildhost() const
Definition: Package.cc:239
#define ERR
Definition: Logger.h:102
OnMediaLocation lookupLocation() const
Definition: SolvableType.h:160
bool maybeUnsupported() const
True if the vendor support for this package is unknown or explicitly unsupported. ...
Definition: Package.cc:154
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:136
static const SolvAttr sourceevr
Definition: SolvAttr.h:121
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition: String.h:531
Edition sourcePkgEdition() const
Edition of the source rpm this package was built from.
Definition: Package.cc:289
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:338
static const SolvAttr url
Definition: SolvAttr.h:123
std::string sourcePkgLongName() const
The source rpms "name-version-release.type".
Definition: Package.cc:299
std::string group() const
Definition: Package.cc:251
std::string packager() const
Definition: Package.cc:248
Package interface.
Definition: Package.h:33
static const SolvAttr license
Definition: SolvAttr.h:112
#define WAR
Definition: Logger.h:101
FileList filelist() const
Return the packages filelist (if available).
Definition: Package.cc:270
The package is known to be unsupported by the vendor.
VendorSupportOption vendorSupport() const
Returns the level of supportability the vendor gives to this package.
Definition: Package.cc:151
static const SolvAttr authors
Definition: SolvAttr.h:117
CheckSum checksum() const
Checksum the source says this package should have.
Definition: Package.cc:273
Keywords keywords() const
Definition: Package.cc:254
Base for resolvable objects.
Definition: ResObject.h:37
unsigned size() const
The strings size.
Definition: IdString.cc:47
~Package() override
Dtor.
Definition: Package.cc:148
static const SolvAttr buildhost
Definition: SolvAttr.h:110
std::string type() const
Definition: CheckSum.cc:167
static const SolvAttr checksum
Definition: SolvAttr.h:105
const Pathname & filename() const
The path to the resource on the medium.
static const SolvAttr sourcename
Definition: SolvAttr.h:120
sat::ArrayAttr< std::string, std::string > FileList
Definition: Package.h:43
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition: Selectable.cc:29
std::pair< VendorSupportOption, std::optional< std::set< std::string_view > >> GetVendorSupportOptionReturn
getVendorSupportOption return value
Definition: Package.cc:31
std::string sourcePkgName() const
Name of the source rpm this package was built from.
Definition: Package.cc:282
bool empty() const
Definition: CheckSum.cc:173
A sat capability.
Definition: Capability.h:62
Additional Customer Contract necessary.
static const SolvAttr sourcesize
Definition: SolvAttr.h:116
c++17: std::string_view tools
unsigned long long lookupNumAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:157
static const SolvAttr keywords
Definition: SolvAttr.h:115
Pathname packagesPath() const
Path where this repo packages are cached.
Definition: RepoInfo.cc:618
std::string license() const
Definition: Package.cc:245
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
static const SolvAttr group
Definition: SolvAttr.h:114
static const SolvAttr filelist
Definition: SolvAttr.h:118
detail::IdType lookupIdAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:156
std::string asString() const
Conversion to std::string
Definition: IdString.h:99
static const SolvAttr distribution
Definition: SolvAttr.h:111
static const std::string & md5Type()
Definition: CheckSum.cc:28
std::string lookupStrAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:153
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
std::list< std::string > authors() const
Definition: Package.cc:263
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1027
zypp::IdString IdString
Definition: idstring.h:16
sat::ArrayAttr< PackageKeyword, IdString > Keywords
Definition: Package.h:42
IdString ident() const
The identifier.
Definition: Solvable.cc:270
Url manipulation class.
Definition: Url.h:92
std::pair< std::vector< IdString >, std::vector< std::string > > supersededByItems() const
The successor package(s) if vendorSupport is VendorSupportSuperseded.
Definition: Package.cc:185