libzypp 17.37.10

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
18#include <zypp/ui/UserWantedPackages.h>
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
28 using std::string;
29 using std::set;
30 using std::endl;
31
32
33 namespace zypp
34{
35 namespace ui
36 {
37 using PoolProxyIterator = ResPoolProxy::const_iterator;
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
64 set<string> userWantedPackageNames()
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
ResObjects.h
ResPoolProxy.h
Selectable.h
UserWantedPackages.h
ZYppFactory.h
zypp::Patch::constPtr
TraitsType::constPtrType constPtr
Definition Patch.h:43
zypp::Patch::Contents
sat::SolvableSet Contents
Definition Patch.h:46
zypp::ResPoolProxy
ResPool::instance().proxy();.
Definition ResPoolProxy.h:36
zypp::ResPoolProxy::byKindBegin
const_iterator byKindBegin(const ResKind &kind_r) const
Definition ResPoolProxy.cc:297
zypp::ResPoolProxy::byKindEnd
const_iterator byKindEnd(const ResKind &kind_r) const
Definition ResPoolProxy.cc:300
zypp::ResPoolProxy::const_iterator
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition ResPoolProxy.h:45
zypp::ResStatus::USER
@ USER
Definition ResStatus.h:112
zypp::ZYppFactory::getZYpp
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
zypp::sat::SolvableSet::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition SolvableSet.h:76
zypp::sat::SolvableSet::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition SolvableSet.h:72
zypp::ui
Definition SolvIterMixin.cc:57
zypp::ui::userWantedPackageNames
set< string > userWantedPackageNames()
This returns a set of package names the user explicitly wanted to transact ( to install,...
Definition UserWantedPackages.cc:64
zypp::ui::PoolProxyIterator
ResPoolProxy::const_iterator PoolProxyIterator
Definition UserWantedPackages.cc:37
zypp::ui::pkgEnd
static PoolProxyIterator pkgEnd()
Definition UserWantedPackages.cc:45
zypp::ui::poolProxyBegin
PoolProxyIterator poolProxyBegin()
Definition UserWantedPackages.cc:41
zypp::ui::pkgBegin
static PoolProxyIterator pkgBegin()
Definition UserWantedPackages.cc:44
zypp::ui::poolProxyEnd
PoolProxyIterator poolProxyEnd()
Definition UserWantedPackages.cc:42
zypp::ui::addDirectlySelectedPackages
static void addDirectlySelectedPackages(set< string > &pkgNames)
Definition UserWantedPackages.cc:78
zypp::ui::patchesBegin
static PoolProxyIterator patchesBegin()
Definition UserWantedPackages.cc:47
zypp::ui::patchesEnd
static PoolProxyIterator patchesEnd()
Definition UserWantedPackages.cc:48
zypp::ui::poolProxy
static ResPoolProxy poolProxy()
Definition UserWantedPackages.cc:39
zypp::ui::contains
bool contains(const std::set< T > &container, T search)
Definition UserWantedPackages.cc:50
zypp::ui::addPatchPackages
static void addPatchPackages(set< string > &pkgNames)
Definition UserWantedPackages.cc:97
zypp::ui::addPkgSetPackages
void addPkgSetPackages(set< string > &pkgNames)
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
DBG
#define DBG
Definition Logger.h:99
Logger.h
PtrTypes.h