libzypp  17.31.0
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 
28 using std::string;
29 using std::set;
30 using std::endl;
31 
32 
33 namespace 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 
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
static PoolProxyIterator pkgBegin()
PoolProxyIterator poolProxyBegin()
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
static PoolProxyIterator patchesEnd()
static void addDirectlySelectedPackages(set< string > &pkgNames)
static void addPatchPackages(set< string > &pkgNames)
Class representing a patch.
Definition: Patch.h:37
ResPool::instance().proxy();.
Definition: ResPoolProxy.h:34
static PoolProxyIterator pkgEnd()
set< string > userWantedPackageNames()
This returns a set of package names the user explicitly wanted to transact ( to install, to update, or to delete) for any of the following reasons:
PoolProxyIterator poolProxyEnd()
const_iterator byKindEnd(const ResKind &kind_r) const
TraitsType::constPtrType constPtr
Definition: Patch.h:43
static PoolProxyIterator patchesBegin()
const_iterator byKindBegin(const ResKind &kind_r) const
void addPkgSetPackages(set< string > &pkgNames)
static ResPoolProxy poolProxy()
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition: ResPoolProxy.h:42
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool contains(const std::set< T > &container, T search)
#define DBG
Definition: Logger.h:95
ResPoolProxy::const_iterator PoolProxyIterator
Solvable set wrapper to allow adding additional convenience iterators.
Definition: SolvableSet.h:35