00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/capability/FilesystemCap.h"
00015
00016 #include "zypp/pool/PoolImpl.h"
00017 #include "zypp/pool/PoolStats.h"
00018 #include "zypp/CapSet.h"
00019 #include "zypp/Package.h"
00020 #include "zypp/VendorAttr.h"
00021
00022 using std::endl;
00023
00025 namespace zypp
00026 {
00027
00028 std::ostream & operator<<( std::ostream & str, const CapAndItem & obj )
00029 {
00030 return str << "{" << obj.cap << ", " << obj.item << "}";
00031 }
00032
00034 namespace pool
00035 {
00036
00038
00039
00040
00041
00042 NameHash::NameHash()
00043 {}
00044
00046
00047
00048
00049
00050 NameHash::~NameHash()
00051 {}
00052
00053 void
00054 NameHash::insert( const PoolItem & item_r )
00055 {
00056 _store[item_r->name()].insert( item_r );
00057 }
00058
00059 void
00060 NameHash::erase( const PoolItem & item_r )
00061 {
00062 PoolTraits::ItemContainerT & items = _store[item_r->name()];
00063 for ( PoolTraits::iterator nit = items.begin(); nit != items.end(); )
00064 {
00065 if ( *nit == item_r )
00066 items.erase( nit++ );
00067 else
00068 ++nit;
00069 }
00070 }
00071
00072 NameHash::ItemContainerT & NameHash::getItemContainer( const std::string & tag_r )
00073 { ContainerT::iterator it = _store.find( tag_r );
00074 if (it == _store.end()) {
00075
00076 return _empty;
00077 }
00078
00079 return it->second;
00080 }
00081
00082 const NameHash::ItemContainerT & NameHash::getConstItemContainer( const std::string & tag_r ) const
00083 { ContainerT::const_iterator it = _store.find( tag_r );
00084 if (it == _store.end()) {
00085
00086 return _empty;
00087 }
00088
00089 return it->second;
00090 }
00091
00093
00094
00095
00096
00097 CapHash::CapHash()
00098 {}
00099
00101
00102
00103
00104
00105 CapHash::~CapHash()
00106 {}
00107
00108 static void
00109 storeInsert( CapHash::ContainerT & store_r, const PoolItem & item_r, Dep cap_r )
00110 {
00111 CapSet caps = item_r->dep( cap_r );
00112 for (CapSet::iterator ic = caps.begin(); ic != caps.end(); ++ic) {
00113 store_r[cap_r][ic->index()].push_back( CapAndItem( *ic, item_r ) );
00114 }
00115 }
00116
00117 void CapHash::insert( const PoolItem & item_r )
00118 {
00119 storeInsert( _store, item_r, Dep::PROVIDES );
00120 storeInsert( _store, item_r, Dep::REQUIRES );
00121 storeInsert( _store, item_r, Dep::CONFLICTS );
00122 storeInsert( _store, item_r, Dep::OBSOLETES );
00123 storeInsert( _store, item_r, Dep::RECOMMENDS );
00124 storeInsert( _store, item_r, Dep::SUGGESTS );
00125 storeInsert( _store, item_r, Dep::FRESHENS );
00126 storeInsert( _store, item_r, Dep::ENHANCES );
00127 storeInsert( _store, item_r, Dep::SUPPLEMENTS );
00128 }
00129
00130 static void
00131 storeDelete( PoolTraits::DepCapItemContainerT & store_r, const PoolItem & item_r, Dep cap_r )
00132 {
00133 CapSet caps = item_r->dep( cap_r );
00134
00135 for ( CapSet::iterator ic = caps.begin(); ic != caps.end(); ++ic )
00136 {
00137 PoolTraits::CapItemContainerT & capitems = store_r[cap_r][ic->index()];
00138 for ( PoolTraits::CapItemContainerT::iterator pos = capitems.begin(); pos != capitems.end(); )
00139 {
00140 if ( pos->item == item_r )
00141 capitems.erase( pos++ );
00142 else
00143 ++pos;
00144 }
00145 }
00146 }
00147
00148 void CapHash::erase( const PoolItem & item_r )
00149 {
00150
00151 storeDelete( _store, item_r, Dep::PROVIDES );
00152 storeDelete( _store, item_r, Dep::REQUIRES );
00153 storeDelete( _store, item_r, Dep::CONFLICTS );
00154 storeDelete( _store, item_r, Dep::OBSOLETES );
00155 storeDelete( _store, item_r, Dep::RECOMMENDS );
00156 storeDelete( _store, item_r, Dep::SUGGESTS );
00157 storeDelete( _store, item_r, Dep::FRESHENS );
00158 storeDelete( _store, item_r, Dep::ENHANCES );
00159 storeDelete( _store, item_r, Dep::SUPPLEMENTS );
00160 }
00161
00162 const CapHash::CapItemStoreT & CapHash::capItemStore ( Dep cap_r ) const
00163 { static CapItemStoreT capitemstore;
00164 ContainerT::const_iterator it = store().find( cap_r );
00165 if (it == store().end()) {
00166
00167 return capitemstore;
00168 }
00169
00170 return it->second;
00171 }
00172
00173
00174 const CapHash::CapItemContainerT & CapHash::capItemContainer( const CapItemStoreT & cis, const std::string & tag_r ) const
00175 { static CapItemContainerT captemcontainer;
00176 CapItemStoreT::const_iterator it = cis.find( tag_r );
00177 if (it == cis.end()) {
00178
00179 return captemcontainer;
00180 }
00181
00182
00183 return it->second;
00184 }
00185
00187
00188
00189
00191
00193
00194
00195
00196
00197 PoolImpl::PoolImpl()
00198 : _watchFilesystemSysconfigStorage( capability::FilesystemCap::sysconfigStorageSerial() )
00199 {}
00200
00202
00203
00204
00205
00206 PoolImpl::~PoolImpl()
00207 {}
00208
00210
00211
00212
00213
00214 const SerialNumber & PoolImpl::serial() const
00215 {
00216 if ( _watchFilesystemSysconfigStorage.remember( capability::FilesystemCap::sysconfigStorageSerial() ) )
00217 {
00218 const_cast<PoolImpl*>(this)->_serial.setDirty();
00219 }
00220 return _serial;
00221 }
00222
00223
00224
00225
00226
00227
00228 std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
00229 {
00230 return dumpPoolStats( str << "ResPool ",
00231 obj.begin(), obj.end() );
00232 }
00233
00234
00235
00236
00237
00238
00242 void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
00243 {
00244
00245
00246
00247 if ( ! ptr_r )
00248 return;
00249
00250 if ( isKind<SrcPackage>( ptr_r ) )
00251 return;
00252
00253 if ( ! _installed )
00254 {
00255
00256
00257
00258 if ( ptr_r->kind() != ResTraits<Atom>::kind ) {
00259 if ( ! ptr_r->arch().compatibleWith( _poolImpl.targetArch() ) )
00260 return;
00261 }
00262 }
00263
00264
00265
00266
00267 PoolImpl::Item item( ptr_r, ResStatus (_installed) );
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 if ( _poolImpl._store.insert( item ).second )
00278 {
00279 _poolImpl._namehash.insert( item );
00280 _poolImpl._caphash.insert( item );
00281
00282 _poolImpl.invalidateProxy();
00283 }
00284 }
00285
00286
00287
00288
00289
00290
00291 void PoolImplDeleter::operator()( ResObject::constPtr ptr_r )
00292 {
00293 PoolImpl::Item item( ptr_r );
00294 _poolImpl._store.erase( item );
00295 _poolImpl._namehash.erase( item );
00296 _poolImpl._caphash.erase( item );
00297
00298
00299 _poolImpl.invalidateProxy();
00300 }
00301
00303 }
00306 }