libzypp  17.14.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 
204  Pathname Package::cachedLocation() const
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