libzypp  12.16.5
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