libzypp 17.31.1
UserWantedPackages.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
15#include <iostream>
16#include <zypp/base/Logger.h>
17
19
20#include <zypp/base/PtrTypes.h>
21#include <zypp/ui/Selectable.h>
22
23#include <zypp/ResObjects.h>
24#include <zypp/ZYppFactory.h>
25#include <zypp/ResPoolProxy.h>
26
27
28using std::string;
29using std::set;
30using std::endl;
31
32
33namespace zypp
34{
35 namespace ui
36 {
38
39 static inline ResPoolProxy poolProxy() { return getZYpp()->poolProxy(); }
40
41 template<class T> PoolProxyIterator poolProxyBegin() { return poolProxy().byKindBegin<T>(); }
42 template<class T> PoolProxyIterator poolProxyEnd() { return poolProxy().byKindEnd<T>(); }
43
44 static inline PoolProxyIterator pkgBegin() { return poolProxyBegin<Package>(); }
45 static inline PoolProxyIterator pkgEnd() { return poolProxyEnd<Package>(); }
46
47 static inline PoolProxyIterator patchesBegin() { return poolProxyBegin<Patch>(); }
48 static inline PoolProxyIterator patchesEnd() { return poolProxyEnd<Patch>(); }
49
50 template<typename T> bool contains( const std::set<T> & container, T search )
51 {
52 return container.find( search ) != container.end();
53 }
54
55
56
57 static void addDirectlySelectedPackages ( set<string> & pkgNames );
58 template<class PkgSet_T> void addPkgSetPackages( set<string> & pkgNames );
59
60 static void addPatchPackages ( set<string> & pkgNames );
61
62
63
65 {
66 set<string> pkgNames;
67
68 DBG << "Collecting packages the user explicitly asked for" << endl;
69
70 addDirectlySelectedPackages ( pkgNames );
71 addPatchPackages ( pkgNames );
72
73 return pkgNames;
74 }
75
76
77
78 static void addDirectlySelectedPackages( set<string> & pkgNames )
79 {
80 for ( PoolProxyIterator it = pkgBegin();
81 it != pkgEnd();
82 ++it )
83 {
84 // Add all packages the user wanted to transact directly,
85 // no matter what the transaction is (install, update, delete)
86
87 if ( (*it)->toModify() && (*it)->modifiedBy() == ResStatus::USER )
88 {
89 DBG << "Explicit user transaction on pkg \"" << (*it)->name() << "\"" << endl;
90
91 pkgNames.insert( (*it)->name() );
92 }
93 }
94 }
95
96
97 static void addPatchPackages( set<string> & pkgNames )
98 {
99 for ( PoolProxyIterator patch_it = patchesBegin();
100 patch_it != patchesEnd();
101 ++patch_it )
102 {
103 Patch::constPtr patch = dynamic_pointer_cast<const Patch>( (*patch_it)->theObj() ? (*patch_it)->theObj().resolvable() : 0 );
104
105 if ( patch && (*patch_it)->toModify() )
106 {
107 DBG << "Patch will be transacted: \"" << patch->name()
108 << "\" - \"" << patch->summary() << "\"" << endl;
109
110 Patch::Contents contents( patch->contents() );
111 for_( it, contents.begin(), contents.end() )
112 {
113 pkgNames.insert( it->name() );
114 }
115 }
116 }
117 }
118
119 } // namespace ui
120} // namespace zypp
TraitsType::constPtrType constPtr
Definition: Patch.h:43
ResPool::instance().proxy();.
Definition: ResPoolProxy.h:35
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition: ResPoolProxy.h:42
const_iterator byKindBegin(const ResKind &kind_r) const
const_iterator byKindEnd(const ResKind &kind_r) const
Solvable set wrapper to allow adding additional convenience iterators.
Definition: SolvableSet.h:36
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: SolvableSet.h:76
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: SolvableSet.h:72
static PoolProxyIterator pkgEnd()
set< string > userWantedPackageNames()
This returns a set of package names the user explicitly wanted to transact ( to install,...
PoolProxyIterator poolProxyBegin()
static PoolProxyIterator pkgBegin()
PoolProxyIterator poolProxyEnd()
static void addDirectlySelectedPackages(set< string > &pkgNames)
static PoolProxyIterator patchesBegin()
ResPoolProxy::const_iterator PoolProxyIterator
static PoolProxyIterator patchesEnd()
static ResPoolProxy poolProxy()
bool contains(const std::set< T > &container, T search)
static void addPatchPackages(set< string > &pkgNames)
void addPkgSetPackages(set< string > &pkgNames)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
#define DBG
Definition: Logger.h:95