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