libzypp  17.22.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 zyppintern
27 {
28  using namespace zypp;
29 
30  inline bool schemeIsLocalDir( const Url & url_r )
31  {
32  const std::string & s( url_r.getScheme() );
33  return s == "dir" || s == "file";
34  }
35 
36  // here and from SrcPackage.cc
37  Pathname cachedLocation( const OnMediaLocation & loc_r, const RepoInfo & repo_r )
38  {
39  PathInfo pi( repo_r.packagesPath() / repo_r.path() / loc_r.filename() );
40 
41  if ( ! pi.isExist() )
42  return Pathname(); // no file in cache
43 
44  if ( loc_r.checksum().empty() )
45  {
46  Url url( repo_r.url() );
47  if ( ! schemeIsLocalDir( url ) )
48  return Pathname(); // same name but no checksum to verify
49 
50  // for local repos compare with the checksum in repo
51  if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / repo_r.path() / loc_r.filename()).c_str() ) )
52  != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
53  return Pathname(); // same name but wrong checksum
54  }
55  else
56  {
57  if ( loc_r.checksum() != CheckSum( loc_r.checksum().type(), std::ifstream( pi.c_str() ) ) )
58  return Pathname(); // same name but wrong checksum
59  }
60 
61  return pi.path(); // the right one
62  }
63 } // namespace zyppintern
65 
67 namespace zypp
68 {
69 
71 
73  //
74  // METHOD NAME : Package::Package
75  // METHOD TYPE : Ctor
76  //
77  Package::Package( const sat::Solvable & solvable_r )
78  : ResObject( solvable_r )
79  {}
80 
82  //
83  // METHOD NAME : Package::~Package
84  // METHOD TYPE : Dtor
85  //
87  {}
88 
90  {
91  static const IdString support_unsupported( "support_unsupported" );
92  static const IdString support_acc( "support_acc" );
93  static const IdString support_l1( "support_l1" );
94  static const IdString support_l2( "support_l2" );
95  static const IdString support_l3( "support_l3" );
96 
98  // max over all identical packages
99  for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
100  {
101  if ( solv.edition() == edition()
102  && solv.ident() == ident()
103  && identical( solv ) )
104  {
105  for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
106  {
107  switch ( ret )
108  {
110  if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
112  if ( kw == support_acc ) { ret = VendorSupportACC; break; }
113  case VendorSupportACC:
114  if ( kw == support_l1 ) { ret = VendorSupportLevel1; break; }
115  case VendorSupportLevel1:
116  if ( kw == support_l2 ) { ret = VendorSupportLevel2; break; }
117  case VendorSupportLevel2:
118  if ( kw == support_l3 ) { return VendorSupportLevel3; break; }
119  case VendorSupportLevel3:
120  /* make gcc happy */ break;
121  }
122  }
123  }
124  }
125  return ret;
126  }
127 
129  {
130  switch ( vendorSupport() )
131  {
134  case VendorSupportACC:
135  return true;
136 
137  case VendorSupportLevel1:
138  case VendorSupportLevel2:
139  case VendorSupportLevel3:
140  break; // intentionally no default:
141  }
142  return false;
143  }
144 
146  {
147  Target_Ptr target( getZYpp()->getTarget() );
148  if ( ! target )
149  {
150  ERR << "Target not initialized. Changelog is not available." << std::endl;
151  return Changelog();
152  }
153 
154  if ( repository().isSystemRepo() )
155  {
157  target->rpmDb().getData(name(), header);
158  return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
159  }
160  WAR << "changelog is not available for uninstalled packages" << std::endl;
161  return Changelog();
162  }
163 
164  std::string Package::buildhost() const
166 
167  std::string Package::distribution() const
169 
170  std::string Package::license() const
172 
173  std::string Package::packager() const
175 
176  std::string Package::group() const
178 
181 
182  std::string Package::url() const
184 
187 
188  std::list<std::string> Package::authors() const
189  {
190  std::list<std::string> ret;
191  str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
192  return ret;
193  }
194 
197 
200 
202  { return lookupLocation(); }
203 
205  { return zyppintern::cachedLocation( location(), repoInfo() ); }
206 
207  std::string Package::sourcePkgName() const
208  {
209  // no id means same as package
211  return id ? IdString( id ).asString() : name();
212  }
213 
215  {
216  // no id means same as package
218  return id ? Edition( id ) : edition();
219  }
220 
221  std::string Package::sourcePkgType() const
223 
224  std::string Package::sourcePkgLongName() const
225  { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
226 
227 
229 } // namespace zypp
zypp::sat::SolvableType< Resolvable >::repository
Repository repository() const
Definition: SolvableType.h:75
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
zypp::Changelog
std::list< ChangelogEntry > Changelog
List of ChangelogEntry.
Definition: Changelog.h:53
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:53
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
zypp::Package::location
OnMediaLocation location() const
Location of the resolvable in the repository.
Definition: Package.cc:201
zyppintern
Definition: Package.cc:26
ZYppFactory.h
zypp::Package::checksum
CheckSum checksum() const
Checksum the source says this package should have.
Definition: Package.cc:198
zypp::Package::distribution
std::string distribution() const
Definition: Package.cc:167
zypp::CheckSum::type
std::string type() const
Definition: CheckSum.cc:167
zypp::VendorSupportLevel2
Problem isolation, which means technical support designed to duplicate customer problems,...
Definition: VendorSupportOptions.h:52
zypp::sat::SolvableType< Resolvable >::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
zypp::CheckSum
Definition: CheckSum.h:33
zypp::sat::SolvableType< Resolvable >::repoInfo
RepoInfo repoInfo() const
Definition: SolvableType.h:76
zypp::RepoInfo
What is known about a repository.
Definition: RepoInfo.h:71
zypp::Package::sourcePkgLongName
std::string sourcePkgLongName() const
The source rpms "name-version-release.type".
Definition: Package.cc:224
RpmHeader.h
zypp::Package::group
std::string group() const
Definition: Package.cc:176
zypp::sat::SolvableType< Resolvable >::edition
Edition edition() const
Definition: SolvableType.h:71
zypp::sat::SolvAttr::packager
static const SolvAttr packager
Definition: SolvAttr.h:94
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition: OnMediaLocation.h:38
zypp::sat::SolvAttr::sourcearch
static const SolvAttr sourcearch
Definition: SolvAttr.h:100
zypp::CheckSum::empty
bool empty() const
Definition: CheckSum.cc:173
zypp::VendorSupportACC
Additional Customer Contract necessary.
Definition: VendorSupportOptions.h:34
zypp::Package::sourcePkgName
std::string sourcePkgName() const
Name of the source rpm this package was built from.
Definition: Package.cc:207
zypp::VendorSupportUnknown
The support for this package is unknown.
Definition: VendorSupportOptions.h:26
zypp::Package::changelog
Changelog changelog() const
Get the package change log.
Definition: Package.cc:145
zypp::OnMediaLocation::checksum
const CheckSum & checksum() const
The checksum of the resource on the server.
Definition: OnMediaLocation.cc:118
zypp::sat::SolvableType< Resolvable >::id
Solvable::IdType id() const
Definition: SolvableType.h:144
zypp::Package::filelist
FileList filelist() const
Return the packages filelist (if available).
Definition: Package.cc:195
zypp::sat::SolvAttr::sourceevr
static const SolvAttr sourceevr
Definition: SolvAttr.h:102
zypp::RepoInfo::packagesPath
Pathname packagesPath() const
Path where this repo packages are cached.
Definition: RepoInfo.cc:652
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:30
zypp::Package::Keywords
sat::ArrayAttr< PackageKeyword, IdString > Keywords
Definition: Package.h:41
zypp::IdString::asString
std::string asString() const
Conversion to std::string
Definition: IdString.h:91
zypp::PackageKeyword
Package keywords.
Definition: PackageKeyword.h:28
zypp::sat::SolvAttr::url
static const SolvAttr url
Definition: SolvAttr.h:104
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:41
zypp::str::split
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition: String.h:527
Package.h
zypp::filesystem::PathInfo
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
zypp::sat::SolvableType< Resolvable >::lookupStrAttribute
std::string lookupStrAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:136
zypp::sat::SolvAttr::license
static const SolvAttr license
Definition: SolvAttr.h:93
zypp::sat::SolvableType< Resolvable >::name
std::string name() const
Definition: SolvableType.h:70
zypp::Package::authors
std::list< std::string > authors() const
Definition: Package.cc:188
Logger.h
WAR
#define WAR
Definition: Logger.h:80
zypp::Package
Package interface.
Definition: Package.h:32
zypp::sat::SolvableType< Resolvable >::lookupNumAttribute
unsigned long long lookupNumAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:140
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition: ReferenceCounted.h:136
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:35
zypp::sat::SolvAttr::buildhost
static const SolvAttr buildhost
Definition: SolvAttr.h:91
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::Package::sourcePkgType
std::string sourcePkgType() const
The type of the source rpm ("src" or "nosrc").
Definition: Package.cc:221
zypp::Package::sourcesize
ByteCount sourcesize() const
Size of corresponding the source package.
Definition: Package.cc:185
zypp::VendorSupportLevel3
Problem resolution, which means technical support designed to resolve complex problems by engaging en...
Definition: VendorSupportOptions.h:60
zypp::sat::SolvableType< Resolvable >::lookupIdAttribute
detail::IdType lookupIdAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:139
zypp::VendorSupportUnsupported
The package is known to be unsupported by the vendor.
Definition: VendorSupportOptions.h:30
zypp::VendorSupportLevel1
Problem determination, which means technical support designed to provide compatibility information,...
Definition: VendorSupportOptions.h:44
zypp::sat::SolvAttr::authors
static const SolvAttr authors
Definition: SolvAttr.h:98
zypp::Package::buildhost
std::string buildhost() const
Definition: Package.cc:164
LookupAttr.h
zypp::sat::SolvAttr::checksum
static const SolvAttr checksum
Definition: SolvAttr.h:86
zypp::sat::ArrayAttr
LookupAttr::TransformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:592
zypp::OnMediaLocation::filename
const Pathname & filename() const
The path to the resource on the medium.
Definition: OnMediaLocation.cc:85
zyppintern::cachedLocation
Pathname cachedLocation(const OnMediaLocation &loc_r, const RepoInfo &repo_r)
Definition: Package.cc:37
zyppintern::schemeIsLocalDir
bool schemeIsLocalDir(const Url &url_r)
Definition: Package.cc:30
zypp::sat::SolvAttr::keywords
static const SolvAttr keywords
Definition: SolvAttr.h:96
zypp::sat::SolvAttr::sourcename
static const SolvAttr sourcename
Definition: SolvAttr.h:101
zypp::Capability
A sat capability.
Definition: Capability.h:59
zypp::Package::keywords
Keywords keywords() const
Definition: Package.cc:179
zypp::Url::getPathName
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:599
zypp::RepoInfo::url
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:131
std
Definition: Arch.h:347
zypp::sat::SolvAttr::group
static const SolvAttr group
Definition: SolvAttr.h:95
zypp::sat::SolvAttr::filelist
static const SolvAttr filelist
Definition: SolvAttr.h:99
zypp::Package::packager
std::string packager() const
Definition: Package.cc:173
Target_Ptr
zypp::sat::SolvableType< Resolvable >::lookupLocation
OnMediaLocation lookupLocation() const
Definition: SolvableType.h:143
String.h
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zypp::sat::SolvAttr::distribution
static const SolvAttr distribution
Definition: SolvAttr.h:92
zypp::sat::SolvAttr::sourcesize
static const SolvAttr sourcesize
Definition: SolvAttr.h:97
ERR
#define ERR
Definition: Logger.h:81
zypp::Package::FileList
sat::ArrayAttr< std::string, std::string > FileList
Definition: Package.h:42
zyppng::IdString
zypp::IdString IdString
Definition: idstring.h:16
zypp::Package::~Package
virtual ~Package()
Dtor.
Definition: Package.cc:86
zypp::sat::SolvableType< Resolvable >::ident
IdString ident() const
Definition: SolvableType.h:61
zypp::Package::license
std::string license() const
Definition: Package.cc:170
zypp::Package::maybeUnsupported
bool maybeUnsupported() const
True if the vendor support for this package is unknown or explictly unsupported.
Definition: Package.cc:128
zypp::sat::SolvableType< Resolvable >::identical
bool identical(const Solvable &rhs) const
Definition: SolvableType.h:93
url
Url url
Definition: MediaCurl.cc:65
zypp::Url
Url manipulation class.
Definition: Url.h:87
zypp::sat::SolvableType< Resolvable >::lookupCheckSumAttribute
CheckSum lookupCheckSumAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:142
zypp::Package::sourcePkgEdition
Edition sourcePkgEdition() const
Edition of the source rpm this package was built from.
Definition: Package.cc:214
RpmDb.h
zypp::Package::cachedLocation
Pathname cachedLocation() const
Location of the downloaded package in cache or an empty path.
Definition: Package.cc:204
zypp::Package::vendorSupport
VendorSupportOption vendorSupport() const
Returns the level of supportability the vendor gives to this package.
Definition: Package.cc:89
zypp::ResObject
Base for resolvable objects.
Definition: ResObject.h:37
zypp::VendorSupportOption
VendorSupportOption
Definition: VendorSupportOptions.h:21
zypp::Package::url
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:182
zypp::RepoInfo::path
Pathname path() const
Repository path.
Definition: RepoInfo.cc:691