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 ///////////////////////////////////////////////////////////////////
30 inline bool schemeIsLocalDir( const Url & url_r )
32 const std::string & s( url_r.getScheme() );
33 return s == "dir" || s == "file";
36 // here and from SrcPackage.cc
37 Pathname cachedLocation( const OnMediaLocation & loc_r, const RepoInfo & repo_r )
39 PathInfo pi( repo_r.packagesPath() / loc_r.filename() );
42 return Pathname(); // no file in cache
44 if ( loc_r.checksum().empty() )
46 Url url( repo_r.url() );
47 if ( ! schemeIsLocalDir( url ) )
48 return Pathname(); // same name but no checksum to verify
50 // for local repos compare with the checksum in repo
51 if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc_r.filename()).c_str() ) )
52 != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
53 return Pathname(); // same name but wrong checksum
57 if ( loc_r.checksum() != CheckSum( loc_r.checksum().type(), std::ifstream( pi.c_str() ) ) )
58 return Pathname(); // same name but wrong checksum
61 return pi.path(); // the right one
63 } // namespace zyppintern
64 ///////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////
68 { /////////////////////////////////////////////////////////////////
70 IMPL_PTR_TYPE(Package);
72 ///////////////////////////////////////////////////////////////////
74 // METHOD NAME : Package::Package
77 Package::Package( const sat::Solvable & solvable_r )
78 : ResObject( solvable_r )
81 ///////////////////////////////////////////////////////////////////
83 // METHOD NAME : Package::~Package
89 VendorSupportOption Package::vendorSupport() const
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" );
97 VendorSupportOption ret( VendorSupportUnknown );
98 // max over all identical packages
99 for ( const auto & solv : sat::WhatProvides( (Capability(ident().id())) ) )
101 if ( solv.edition() == edition()
102 && solv.ident() == ident()
103 && identical( solv ) )
105 for ( PackageKeyword kw : Keywords( sat::SolvAttr::keywords, solv ) )
109 case VendorSupportUnknown:
110 if ( kw == support_unsupported ) { ret = VendorSupportUnsupported; break; }
111 case VendorSupportUnsupported:
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;
128 bool Package::maybeUnsupported() const
130 static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
131 | VendorSupportUnsupported
132 | VendorSupportACC );
133 return unsupportedOpts.testFlag( vendorSupport() );
136 Changelog Package::changelog() const
138 Target_Ptr target( getZYpp()->getTarget() );
141 ERR << "Target not initialized. Changelog is not available." << std::endl;
145 if ( repository().isSystemRepo() )
147 target::rpm::RpmHeader::constPtr header;
148 target->rpmDb().getData(name(), header);
149 return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
151 WAR << "changelog is not available for uninstalled packages" << std::endl;
155 std::string Package::buildhost() const
156 { return lookupStrAttribute( sat::SolvAttr::buildhost ); }
158 std::string Package::distribution() const
159 { return lookupStrAttribute( sat::SolvAttr::distribution ); }
161 std::string Package::license() const
162 { return lookupStrAttribute( sat::SolvAttr::license ); }
164 std::string Package::packager() const
165 { return lookupStrAttribute( sat::SolvAttr::packager ); }
167 std::string Package::group() const
168 { return lookupStrAttribute( sat::SolvAttr::group ); }
170 Package::Keywords Package::keywords() const
171 { return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
173 std::string Package::url() const
174 { return lookupStrAttribute( sat::SolvAttr::url ); }
176 ByteCount Package::sourcesize() const
177 { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
179 std::list<std::string> Package::authors() const
181 std::list<std::string> ret;
182 str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
186 Package::FileList Package::filelist() const
187 { return FileList( sat::SolvAttr::filelist, satSolvable() ); }
189 CheckSum Package::checksum() const
190 { return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
192 OnMediaLocation Package::location() const
193 { return lookupLocation(); }
195 Pathname Package::cachedLocation() const
196 { return zyppintern::cachedLocation( location(), repoInfo() ); }
198 std::string Package::sourcePkgName() const
200 // no id means same as package
201 sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
202 return id ? IdString( id ).asString() : name();
205 Edition Package::sourcePkgEdition() const
207 // no id means same as package
208 sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
209 return id ? Edition( id ) : edition();
212 std::string Package::sourcePkgType() const
213 { return lookupStrAttribute( sat::SolvAttr::sourcearch ); }
215 std::string Package::sourcePkgLongName() const
216 { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
219 /////////////////////////////////////////////////////////////////
221 ///////////////////////////////////////////////////////////////////