1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Package.cc
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"
21 #include "zypp/target/rpm/RpmHeader.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 IMPL_PTR_TYPE(Package);
31 ///////////////////////////////////////////////////////////////////
33 // METHOD NAME : Package::Package
36 Package::Package( const sat::Solvable & solvable_r )
37 : ResObject( solvable_r )
40 ///////////////////////////////////////////////////////////////////
42 // METHOD NAME : Package::~Package
48 VendorSupportOption Package::vendorSupport() const
50 static const IdString support_unsupported( "support_unsupported" );
51 static const IdString support_acc( "support_acc" );
52 static const IdString support_l1( "support_l1" );
53 static const IdString support_l2( "support_l2" );
54 static const IdString support_l3( "support_l3" );
56 VendorSupportOption ret( VendorSupportUnknown );
57 // max over all identical packages
58 for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
60 if ( solv.edition() == edition()
61 && solv.ident() == ident()
62 && identical( solv ) )
64 for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
68 case VendorSupportUnknown:
69 if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
70 case VendorSupportUnsupported:
71 if ( kw == support_acc ) { ret = VendorSupportACC; break; }
72 case VendorSupportACC:
73 if ( kw == support_l1 ) { ret = VendorSupportLevel1; break; }
74 case VendorSupportLevel1:
75 if ( kw == support_l2 ) { ret = VendorSupportLevel2; break; }
76 case VendorSupportLevel2:
77 if ( kw == support_l3 ) { return VendorSupportLevel3; break; }
78 case VendorSupportLevel3:
79 /* make gcc happy */ break;
87 bool Package::maybeUnsupported() const
89 static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
90 | VendorSupportUnsupported
92 return unsupportedOpts.testFlag( vendorSupport() );
95 Changelog Package::changelog() const
97 Target_Ptr target( getZYpp()->getTarget() );
100 ERR << "Target not initialized. Changelog is not available." << std::endl;
104 if ( repository().isSystemRepo() )
106 target::rpm::RpmHeader::constPtr header;
107 target->rpmDb().getData(name(), header);
108 return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
110 WAR << "changelog is not available for uninstalled packages" << std::endl;
114 std::string Package::buildhost() const
115 { return lookupStrAttribute( sat::SolvAttr::buildhost ); }
117 std::string Package::distribution() const
118 { return lookupStrAttribute( sat::SolvAttr::distribution ); }
120 std::string Package::license() const
121 { return lookupStrAttribute( sat::SolvAttr::license ); }
123 std::string Package::packager() const
124 { return lookupStrAttribute( sat::SolvAttr::packager ); }
126 std::string Package::group() const
127 { return lookupStrAttribute( sat::SolvAttr::group ); }
129 Package::Keywords Package::keywords() const
130 { return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
132 std::string Package::url() const
133 { return lookupStrAttribute( sat::SolvAttr::url ); }
135 ByteCount Package::sourcesize() const
136 { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
138 std::list<std::string> Package::authors() const
140 std::list<std::string> ret;
141 str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
145 Package::FileList Package::filelist() const
146 { return FileList( sat::SolvAttr::filelist, satSolvable() ); }
148 CheckSum Package::checksum() const
149 { return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
151 OnMediaLocation Package::location() const
152 { return lookupLocation(); }
156 bool schemeIsLocalDir( const Url & url_r )
158 std::string s( url_r.getScheme() );
159 return s == "dir" || s == "file";
163 Pathname Package::cachedLocation() const
165 OnMediaLocation loc( location() );
166 PathInfo pi( repoInfo().packagesPath() / loc.filename() );
168 if ( ! pi.isExist() )
169 return Pathname(); // no file in cache
171 if ( loc.checksum().empty() )
173 Url url( repoInfo().url() );
174 if ( ! schemeIsLocalDir( url ) )
175 return Pathname(); // same name but no checksum to verify
177 // for local repos compare with the checksum in repo
178 if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc.filename()).c_str() ) )
179 != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
180 return Pathname(); // same name but wrong checksum
184 if ( loc.checksum() != CheckSum( loc.checksum().type(), std::ifstream( pi.c_str() ) ) )
185 return Pathname(); // same name but wrong checksum
188 return pi.path(); // the right one
191 std::string Package::sourcePkgName() const
193 // no id means same as package
194 sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
195 return id ? IdString( id ).asString() : name();
198 Edition Package::sourcePkgEdition() const
200 // no id means same as package
201 sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
202 return id ? Edition( id ) : edition();
205 std::string Package::sourcePkgType() const
206 { return lookupStrAttribute( sat::SolvAttr::sourcearch ); }
208 std::string Package::sourcePkgLongName() const
209 { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
212 /////////////////////////////////////////////////////////////////
214 ///////////////////////////////////////////////////////////////////