libzypp  15.3.0
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/Logger.h"
16 #include "zypp/base/String.h"
17 #include "zypp/Package.h"
18 #include "zypp/sat/LookupAttr.h"
19 #include "zypp/ZYppFactory.h"
20 #include "zypp/target/rpm/RpmDb.h"
22 
23 using namespace std;
24 
26 namespace zypp
27 {
28 
29  IMPL_PTR_TYPE(Package);
30 
32  //
33  // METHOD NAME : Package::Package
34  // METHOD TYPE : Ctor
35  //
36  Package::Package( const sat::Solvable & solvable_r )
37  : ResObject( solvable_r )
38  {}
39 
41  //
42  // METHOD NAME : Package::~Package
43  // METHOD TYPE : Dtor
44  //
46  {}
47 
49  {
50  static const IdString support_unsupported( "support_unsupported" );
51  static const IdString support_acc( "support_acc" );
52  static const IdString support_l1( "support_l1" );
53  static const IdString support_l2( "support_l2" );
54  static const IdString support_l3( "support_l3" );
55 
57  // max over all identical packages
58  for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
59  {
60  if ( solv.edition() == edition()
61  && solv.ident() == ident()
62  && identical( solv ) )
63  {
64  for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
65  {
66  switch ( ret )
67  {
69  if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
71  if ( kw == support_acc ) { ret = VendorSupportACC; break; }
72  case VendorSupportACC:
73  if ( kw == support_l1 ) { ret = VendorSupportLevel1; break; }
75  if ( kw == support_l2 ) { ret = VendorSupportLevel2; break; }
77  if ( kw == support_l3 ) { return VendorSupportLevel3; break; }
79  /* make gcc happy */ break;
80  }
81  }
82  }
83  }
84  return ret;
85  }
86 
88  {
89  static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
91  | VendorSupportACC );
92  return unsupportedOpts.testFlag( vendorSupport() );
93  }
94 
96  {
97  Target_Ptr target( getZYpp()->getTarget() );
98  if ( ! target )
99  {
100  ERR << "Target not initialized. Changelog is not available." << std::endl;
101  return Changelog();
102  }
103 
104  if ( repository().isSystemRepo() )
105  {
107  target->rpmDb().getData(name(), header);
108  return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
109  }
110  WAR << "changelog is not available for uninstalled packages" << std::endl;
111  return Changelog();
112  }
113 
114  std::string Package::buildhost() const
116 
117  std::string Package::distribution() const
119 
120  std::string Package::license() const
122 
123  std::string Package::packager() const
125 
126  std::string Package::group() const
128 
131 
132  std::string Package::url() const
134 
137 
138  std::list<std::string> Package::authors() const
139  {
140  std::list<std::string> ret;
141  str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
142  return ret;
143  }
144 
147 
150 
152  { return lookupLocation(); }
153 
154  namespace
155  {
156  bool schemeIsLocalDir( const Url & url_r )
157  {
158  std::string s( url_r.getScheme() );
159  return s == "dir" || s == "file";
160  }
161  }
162 
163  Pathname Package::cachedLocation() const
164  {
165  OnMediaLocation loc( location() );
166  PathInfo pi( repoInfo().packagesPath() / loc.filename() );
167 
168  if ( ! pi.isExist() )
169  return Pathname(); // no file in cache
170 
171  if ( loc.checksum().empty() )
172  {
173  Url url( repoInfo().url() );
174  if ( ! schemeIsLocalDir( url ) )
175  return Pathname(); // same name but no checksum to verify
176 
177  // for local repos compare with the checksum in repo
178  if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc.filename()).c_str() ) )
179  != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
180  return Pathname(); // same name but wrong checksum
181  }
182  else
183  {
184  if ( loc.checksum() != CheckSum( loc.checksum().type(), std::ifstream( pi.c_str() ) ) )
185  return Pathname(); // same name but wrong checksum
186  }
187 
188  return pi.path(); // the right one
189  }
190 
191  std::string Package::sourcePkgName() const
192  {
193  // no id means same as package
195  return id ? IdString( id ).asString() : name();
196  }
197 
199  {
200  // no id means same as package
202  return id ? Edition( id ) : edition();
203  }
204 
205  std::string Package::sourcePkgType() const
207 
208  std::string Package::sourcePkgLongName() const
209  { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
210 
211 
213 } // namespace zypp
Package keywords.
int IdType
Generic Id type.
Definition: PoolMember.h:82
A Solvable object within the sat Pool.
Definition: Solvable.h:55
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
std::string sourcePkgName() const
Name of the source rpm this package was built from.
Definition: Package.cc:191
bool empty() const
Definition: CheckSum.cc:173
VendorSupportOption vendorSupport() const
Returns the level of supportability the vendor gives to this package.
Definition: Package.cc:48
Describes a path on a certain media amongs as the information required to download it...
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.
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:471
Repository repository() const
Definition: ResObject.h:184
std::string license() const
Definition: Package.cc:120
Store and operate with byte count.
Definition: ByteCount.h:30
OnMediaLocation location() const
Location of the resolvable in the repository.
Definition: Package.cc:151
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:598
std::list< ChangelogEntry > Changelog
List of ChangelogEntry.
Definition: Changelog.h:53
FileList filelist() const
Return the packages filelist (if available).
Definition: Package.cc:145
std::string lookupStrAttribute(const SolvAttr &attr) const
returns the string attribute value for attr or an empty string if it does not exists.
Definition: Solvable.cc:144
The support for this package is unknown.
std::string url() const
Don't ship it as class Url, because it might be in fact anything but a legal Url. ...
Definition: Package.cc:132
sat::ArrayAttr< PackageKeyword, IdString > Keywords
Definition: Package.h:41
bool maybeUnsupported() const
True if the vendor support for this package is unknown or explictly unsupported.
Definition: Package.cc:87
Definition: Arch.h:330
static const SolvAttr packager
Definition: SolvAttr.h:94
Problem resolution, which means technical support designed to resolve complex problems by engaging en...
Access to the sat-pools string space.
Definition: IdString.h:39
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:595
static const SolvAttr sourcearch
Definition: SolvAttr.h:100
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
std::list< std::string > authors() const
Definition: Package.cc:138
#define ERR
Definition: Logger.h:66
detail::IdType lookupIdAttribute(const SolvAttr &attr) const
returns the id attribute value for attr or detail::noId if it does not exists.
Definition: Solvable.cc:182
IdString ident() const
Definition: Resolvable.h:60
std::string asString() const
Conversion to std::string
Definition: IdString.h:83
ByteCount sourcesize() const
Size of corresponding the source package.
Definition: Package.cc:135
static const SolvAttr sourceevr
Definition: SolvAttr.h:102
Edition sourcePkgEdition() const
Edition of the source rpm this package was built from.
Definition: Package.cc:198
std::string name() const
Definition: Resolvable.h:73
virtual ~Package()
Dtor.
Definition: Package.cc:45
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:230
CheckSum lookupCheckSumAttribute(const SolvAttr &attr) const
returns the CheckSum attribute value for attr or an empty CheckSum if ir does not exist...
Definition: Solvable.cc:188
static const SolvAttr url
Definition: SolvAttr.h:104
Keywords keywords() const
Definition: Package.cc:129
static const SolvAttr license
Definition: SolvAttr.h:93
const sat::Solvable & satSolvable() const
Access the corresponding ::Solvable.
Definition: Resolvable.h:136
#define WAR
Definition: Logger.h:65
RepoInfo repoInfo() const
RepoInfo associated with the repository providing this resolvable.
Definition: ResObject.h:190
std::string packager() const
Definition: Package.cc:123
The package is known to be unsupported by the vendor.
unsigned long long lookupNumAttribute(const SolvAttr &attr) const
returns the numeric attribute value for attr or 0 if it does not exists.
Definition: Solvable.cc:170
static const SolvAttr authors
Definition: SolvAttr.h:98
Interface base for resolvable objects (common data).
Definition: ResObject.h:44
static const SolvAttr buildhost
Definition: SolvAttr.h:91
static const SolvAttr checksum
Definition: SolvAttr.h:86
std::string type() const
Definition: CheckSum.cc:167
std::string group() const
Definition: Package.cc:126
static const SolvAttr sourcename
Definition: SolvAttr.h:101
std::string sourcePkgType() const
The type of the source rpm ("src" or "nosrc").
Definition: Package.cc:205
A sat capability.
Definition: Capability.h:59
const Pathname & filename() const
The path to the resource relatve to the url and path.
Additional Customer Contract necessary.
static const SolvAttr sourcesize
Definition: SolvAttr.h:97
std::string sourcePkgLongName() const
The source rpms "name-version-release.type".
Definition: Package.cc:208
static const SolvAttr keywords
Definition: SolvAttr.h:96
std::string buildhost() const
Definition: Package.cc:114
static const SolvAttr group
Definition: SolvAttr.h:95
static const SolvAttr filelist
Definition: SolvAttr.h:99
Pathname cachedLocation() const
Location of the downloaded package in cache or an empty path.
Definition: Package.cc:163
Edition edition() const
Definition: Resolvable.h:76
IdType id() const
Expert backdoor.
Definition: Solvable.h:288
sat::ArrayAttr< std::string, std::string > FileList
Definition: Package.h:42
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
static const SolvAttr distribution
Definition: SolvAttr.h:92
static const std::string & md5Type()
Definition: CheckSum.cc:28
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::string distribution() const
Definition: Package.cc:117
Url manipulation class.
Definition: Url.h:87
Changelog changelog() const
Get the package change log.
Definition: Package.cc:95
#define IMPL_PTR_TYPE(NAME)
const CheckSum & checksum() const
the checksum of the resource
bool identical(Solvable rhs) const
Test whether two Solvables have the same content.
Definition: Solvable.cc:489
CheckSum checksum() const
Checksum the source says this package should have.
Definition: Package.cc:148