/
Package.cc
214 lines (179 loc) · 6.77 KB
/
Package.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
/** \file zypp/Package.cc
*
*/
#include <iostream>
#include <fstream>
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
#include "zypp/Package.h"
#include "zypp/sat/LookupAttr.h"
#include "zypp/ZYppFactory.h"
#include "zypp/target/rpm/RpmDb.h"
#include "zypp/target/rpm/RpmHeader.h"
using namespace std;
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
IMPL_PTR_TYPE(Package);
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Package::Package
// METHOD TYPE : Ctor
//
Package::Package( const sat::Solvable & solvable_r )
: ResObject( solvable_r )
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Package::~Package
// METHOD TYPE : Dtor
//
Package::~Package()
{}
VendorSupportOption Package::vendorSupport() const
{
static const IdString support_unsupported( "support_unsupported" );
static const IdString support_acc( "support_acc" );
static const IdString support_l1( "support_l1" );
static const IdString support_l2( "support_l2" );
static const IdString support_l3( "support_l3" );
VendorSupportOption ret( VendorSupportUnknown );
// max over all identical packages
for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
{
if ( solv.edition() == edition()
&& solv.ident() == ident()
&& identical( solv ) )
{
for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
{
switch ( ret )
{
case VendorSupportUnknown:
if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
case VendorSupportUnsupported:
if ( kw == support_acc ) { ret = VendorSupportACC; break; }
case VendorSupportACC:
if ( kw == support_l1 ) { ret = VendorSupportLevel1; break; }
case VendorSupportLevel1:
if ( kw == support_l2 ) { ret = VendorSupportLevel2; break; }
case VendorSupportLevel2:
if ( kw == support_l3 ) { return VendorSupportLevel3; break; }
case VendorSupportLevel3:
/* make gcc happy */ break;
}
}
}
}
return ret;
}
bool Package::maybeUnsupported() const
{
static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
| VendorSupportUnsupported
| VendorSupportACC );
return unsupportedOpts.testFlag( vendorSupport() );
}
Changelog Package::changelog() const
{
Target_Ptr target( getZYpp()->getTarget() );
if ( ! target )
{
ERR << "Target not initialized. Changelog is not available." << std::endl;
return Changelog();
}
if ( repository().isSystemRepo() )
{
target::rpm::RpmHeader::constPtr header;
target->rpmDb().getData(name(), header);
return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
}
WAR << "changelog is not available for uninstalled packages" << std::endl;
return Changelog();
}
std::string Package::buildhost() const
{ return lookupStrAttribute( sat::SolvAttr::buildhost ); }
std::string Package::distribution() const
{ return lookupStrAttribute( sat::SolvAttr::distribution ); }
std::string Package::license() const
{ return lookupStrAttribute( sat::SolvAttr::license ); }
std::string Package::packager() const
{ return lookupStrAttribute( sat::SolvAttr::packager ); }
std::string Package::group() const
{ return lookupStrAttribute( sat::SolvAttr::group ); }
Package::Keywords Package::keywords() const
{ return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
std::string Package::url() const
{ return lookupStrAttribute( sat::SolvAttr::url ); }
ByteCount Package::sourcesize() const
{ return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
std::list<std::string> Package::authors() const
{
std::list<std::string> ret;
str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
return ret;
}
Package::FileList Package::filelist() const
{ return FileList( sat::SolvAttr::filelist, satSolvable() ); }
CheckSum Package::checksum() const
{ return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
OnMediaLocation Package::location() const
{ return lookupLocation(); }
namespace
{
bool schemeIsLocalDir( const Url & url_r )
{
std::string s( url_r.getScheme() );
return s == "dir" || s == "file";
}
}
Pathname Package::cachedLocation() const
{
OnMediaLocation loc( location() );
PathInfo pi( repoInfo().packagesPath() / loc.filename() );
if ( ! pi.isExist() )
return Pathname(); // no file in cache
if ( loc.checksum().empty() )
{
Url url( repoInfo().url() );
if ( ! schemeIsLocalDir( url ) )
return Pathname(); // same name but no checksum to verify
// for local repos compare with the checksum in repo
if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc.filename()).c_str() ) )
!= CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
return Pathname(); // same name but wrong checksum
}
else
{
if ( loc.checksum() != CheckSum( loc.checksum().type(), std::ifstream( pi.c_str() ) ) )
return Pathname(); // same name but wrong checksum
}
return pi.path(); // the right one
}
std::string Package::sourcePkgName() const
{
// no id means same as package
sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
return id ? IdString( id ).asString() : name();
}
Edition Package::sourcePkgEdition() const
{
// no id means same as package
sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
return id ? Edition( id ) : edition();
}
std::string Package::sourcePkgType() const
{ return lookupStrAttribute( sat::SolvAttr::sourcearch ); }
std::string Package::sourcePkgLongName() const
{ return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////