libzypp  13.10.6
Package.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <fstream>
13 
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/String.h"
16 #include "zypp/Package.h"
17 #include "zypp/sat/LookupAttr.h"
18 #include "zypp/ZYppFactory.h"
19 #include "zypp/target/rpm/RpmDb.h"
21 
22 using namespace std;
23 
25 namespace zypp
26 {
27 
28  IMPL_PTR_TYPE(Package);
29 
31  //
32  // METHOD NAME : Package::Package
33  // METHOD TYPE : Ctor
34  //
35  Package::Package( const sat::Solvable & solvable_r )
36  : ResObject( solvable_r )
37  {}
38 
40  //
41  // METHOD NAME : Package::~Package
42  // METHOD TYPE : Dtor
43  //
45  {}
46 
48  {
49  static const IdString support_unsupported( "support_unsupported" );
50  static const IdString support_acc( "support_acc" );
51  static const IdString support_l1( "support_l1" );
52  static const IdString support_l2( "support_l2" );
53  static const IdString support_l3( "support_l3" );
54 
56  // max over all identical packages
57  for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
58  {
59  if ( solv.edition() == edition()
60  && solv.ident() == ident()
61  && identical( solv ) )
62  {
63  for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
64  {
65  switch ( ret )
66  {
68  if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
70  if ( kw == support_acc ) { ret = VendorSupportACC; break; }
71  case VendorSupportACC:
72  if ( kw == support_l1 ) { ret = VendorSupportLevel1; break; }
74  if ( kw == support_l2 ) { ret = VendorSupportLevel2; break; }
76  if ( kw == support_l3 ) { return VendorSupportLevel3; break; }
78  /* make gcc happy */ break;
79  }
80  }
81  }
82  }
83  return ret;
84  }
85 
87  {
88  static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
90  | VendorSupportACC );
91  return unsupportedOpts.testFlag( vendorSupport() );
92  }
93 
95  {
96  Target_Ptr target( getZYpp()->getTarget() );
97  if ( ! target )
98  {
99  ERR << "Target not initialized. Changelog is not available." << std::endl;
100  return Changelog();
101  }
102 
103  if ( repository().isSystemRepo() )
104  {
106  target->rpmDb().getData(name(), header);
107  return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
108  }
109  WAR << "changelog is not available for uninstalled packages" << std::endl;
110  return Changelog();
111  }
112 
113  std::string Package::buildhost() const
115 
116  std::string Package::distribution() const
118 
119  std::string Package::license() const
121 
122  std::string Package::packager() const
124 
125  std::string Package::group() const
127 
130 
131  std::string Package::url() const
133 
136 
137  std::list<std::string> Package::authors() const
138  {
139  std::list<std::string> ret;
140  str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
141  return ret;
142  }
143 
146 
149 
151  { return lookupLocation(); }
152 
153  namespace
154  {
155  bool schemeIsLocalDir( const Url & url_r )
156  {
157  std::string s( url_r.getScheme() );
158  return s == "dir" || s == "file";
159  }
160  }
161 
162  Pathname Package::cachedLocation() const
163  {
164  OnMediaLocation loc( location() );
165  PathInfo pi( repoInfo().packagesPath() / loc.filename() );
166 
167  if ( ! pi.isExist() )
168  return Pathname(); // no file in cache
169 
170  if ( loc.checksum().empty() )
171  {
172  Url url( repoInfo().url() );
173  if ( ! schemeIsLocalDir( url ) )
174  return Pathname(); // same name but no checksum to verify
175 
176  // for local repos compare with the checksum in repo
177  if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc.filename()).c_str() ) )
178  != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
179  return Pathname(); // same name but wrong checksum
180  }
181  else
182  {
183  if ( loc.checksum() != CheckSum( loc.checksum().type(), std::ifstream( pi.c_str() ) ) )
184  return Pathname(); // same name but wrong checksum
185  }
186 
187  return pi.path(); // the right one
188  }
189 
190  std::string Package::sourcePkgName() const
191  {
192  // no id means same as package
194  return id ? IdString( id ).asString() : name();
195  }
196 
198  {
199  // no id means same as package
201  return id ? Edition( id ) : edition();
202  }
203 
204  std::string Package::sourcePkgType() const
206 
207  std::string Package::sourcePkgLongName() const
208  { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
209 
210 
212 } // 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:65
std::string sourcePkgName() const
Name of the source rpm this package was built from.
Definition: Package.cc:190
bool empty() const
Definition: CheckSum.cc:137
VendorSupportOption vendorSupport() const
Returns the level of supportability the vendor gives to this package.
Definition: Package.cc:47
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:394
Repository repository() const
Definition: ResObject.h:169
std::string license() const
Definition: Package.cc:119
Store and operate with byte count.
Definition: ByteCount.h:30
OnMediaLocation location() const
Location of the resolvable in the repository.
Definition: Package.cc:150
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:144
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:171
The support for this package is unknown.
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:131
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:86
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::list< std::string > authors() const
Definition: Package.cc:137
#define ERR
Definition: Logger.h:49
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:209
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:134
static const SolvAttr sourceevr
Definition: SolvAttr.h:102
Edition sourcePkgEdition() const
Edition of the source rpm this package was built from.
Definition: Package.cc:197
std::string name() const
Definition: Resolvable.h:73
virtual ~Package()
Dtor.
Definition: Package.cc:44
OnMediaLocation lookupLocation() const
returns OnMediaLocation data: This is everything we need to download e.g.
Definition: Solvable.cc:254
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:215
static const SolvAttr url
Definition: SolvAttr.h:104
Keywords keywords() const
Definition: Package.cc:128
static const SolvAttr license
Definition: SolvAttr.h:93
const sat::Solvable & satSolvable() const
Access the corresponding ::Solvable.
Definition: Resolvable.h:133
#define WAR
Definition: Logger.h:48
RepoInfo repoInfo() const
RepoInfo associated with the repository providing this resolvable.
Definition: ResObject.h:175
std::string packager() const
Definition: Package.cc:122
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:197
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:131
std::string group() const
Definition: Package.cc:125
static const SolvAttr sourcename
Definition: SolvAttr.h:101
std::string form(const char *format,...)
Printf style construction of std::string.
Definition: String.cc:34
std::string sourcePkgType() const
The type of the source rpm (&quot;src&quot; or &quot;nosrc&quot;).
Definition: Package.cc:204
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 &quot;name-version-release.type&quot;.
Definition: Package.cc:207
static const SolvAttr keywords
Definition: SolvAttr.h:96
std::string buildhost() const
Definition: Package.cc:113
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:162
Edition edition() const
Definition: Resolvable.h:76
IdType id() const
Expert backdoor.
Definition: Solvable.h:296
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
std::string distribution() const
Definition: Package.cc:116
Url manipulation class.
Definition: Url.h:87
Changelog changelog() const
Get the package change log.
Definition: Package.cc:94
#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:525
CheckSum checksum() const
Checksum the source says this package should have.
Definition: Package.cc:147