- Invalidate ResPoolProxy only if pool content changes.
[platform/upstream/libzypp.git] / zypp / pool / PoolImpl.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/pool/PoolImpl.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/pool/PoolImpl.h"
16 #include "zypp/CapSet.h"
17
18 using std::endl;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   namespace pool
25   { /////////////////////////////////////////////////////////////////
26
27     ///////////////////////////////////////////////////////////////////
28     //
29     //  METHOD NAME : PoolImpl::PoolImpl
30     //  METHOD TYPE : Ctor
31     //
32     PoolImpl::PoolImpl()
33     {}
34
35     ///////////////////////////////////////////////////////////////////
36     //
37     //  METHOD NAME : PoolImpl::~PoolImpl
38     //  METHOD TYPE : Dtor
39     //
40     PoolImpl::~PoolImpl()
41     {}
42
43     /******************************************************************
44     **
45     **  FUNCTION NAME : operator<<
46     **  FUNCTION TYPE : std::ostream &
47     */
48     std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
49     {
50       return str << "PoolImpl " << obj.size();
51     }
52
53     void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
54     {
55       PoolImpl::Item item ( ptr_r, ResStatus (_installed) );
56       _poolImpl.store().insert( item );
57       _poolImpl.namestore().insert( PoolImpl::NameContainerT::value_type (item->name(), item ) );
58       CapSet provides = item->dep( Dep::PROVIDES );
59       for (CapSet::iterator ic = provides.begin(); ic != provides.end(); ++ic) {
60         _poolImpl.providesstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
61       }
62       CapSet requires = item->dep( Dep::REQUIRES );
63       for (CapSet::iterator ic = requires.begin(); ic != requires.end(); ++ic) {
64         _poolImpl.requiresstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
65       }
66       CapSet conflicts = item->dep( Dep::CONFLICTS );
67       for (CapSet::iterator ic = conflicts.begin(); ic != conflicts.end(); ++ic) {
68         _poolImpl.conflictsstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
69       }
70
71       // don't miss to invalidate ResPoolProxy
72       _poolImpl.invalidateProxy();
73     }
74
75     void PoolImplDeleter::operator()( ResObject::constPtr ptr_r )
76     {
77       PoolImpl::Item item( ptr_r );
78       _poolImpl.store().erase( item );
79       for (PoolImpl::nameiterator nit = _poolImpl.namestore().lower_bound (item->name());
80                                   nit != _poolImpl.namestore().upper_bound (item->name()); ++nit)
81       {
82         if (nit->second == item)
83             _poolImpl.namestore().erase( nit );
84       }
85       CapSet provides = ptr_r->dep( Dep::PROVIDES );
86       for (CapSet::iterator ic = provides.begin(); ic != provides.end(); ++ic) {
87         for (PoolImpl::indexiterator iit = _poolImpl.providesstore().lower_bound (ic->index());
88                            iit != _poolImpl.providesstore().upper_bound (ic->index()); ++iit)
89         {
90             if (iit->second.second == item)
91                 _poolImpl.providesstore().erase( iit );
92         }
93       }
94       CapSet requires = ptr_r->dep( Dep::REQUIRES );
95       for (CapSet::iterator ic = requires.begin(); ic != requires.end(); ++ic) {
96         for (PoolImpl::indexiterator iit = _poolImpl.requiresstore().lower_bound (ic->index());
97                            iit != _poolImpl.requiresstore().upper_bound (ic->index()); ++iit)
98         {
99             if (iit->second.second == item)
100                 _poolImpl.requiresstore().erase( iit );
101         }
102       }
103       CapSet conflicts = ptr_r->dep( Dep::CONFLICTS );
104       for (CapSet::iterator ic = conflicts.begin(); ic != conflicts.end(); ++ic) {
105         for (PoolImpl::indexiterator iit = _poolImpl.conflictsstore().lower_bound (ic->index());
106                            iit != _poolImpl.conflictsstore().upper_bound (ic->index()); ++iit)
107         {
108             if (iit->second.second == item)
109                 _poolImpl.conflictsstore().erase( iit );
110         }
111       }
112
113       // don't miss to invalidate ResPoolProxy
114       _poolImpl.invalidateProxy();
115     }
116
117     /////////////////////////////////////////////////////////////////
118   } // namespace pool
119   ///////////////////////////////////////////////////////////////////
120   /////////////////////////////////////////////////////////////////
121 } // namespace zypp
122 ///////////////////////////////////////////////////////////////////