work for bug 149869
[platform/upstream/libzypp.git] / zypp / target / TargetImpl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/TargetImpl.h
10  *
11 */
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/ResStore.h"
21
22 #include "zypp/Pathname.h"
23 #include "zypp/media/MediaAccess.h"
24 #include "zypp/Target.h"
25 #include "zypp/target/rpm/RpmDb.h"
26 #include "zypp/target/store/PersistentStorage.h"
27 #include "zypp/solver/detail/Types.h"
28
29 #define STORAGE_DISABLED
30
31 ///////////////////////////////////////////////////////////////////
32 namespace zypp
33 { /////////////////////////////////////////////////////////////////
34   ///////////////////////////////////////////////////////////////////
35   namespace target
36   { /////////////////////////////////////////////////////////////////
37
38     DEFINE_PTR_TYPE(TargetImpl);
39
40     ///////////////////////////////////////////////////////////////////
41     //
42     //  CLASS NAME : TargetImpl
43     //
44     /** Base class for concrete Target implementations.
45      *
46      * Constructed by \ref TargetFactory. Public access via \ref Target
47      * interface.
48     */
49     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
50     {
51       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
52
53     private:
54       /** Sort according to prereqs and media numbers */
55       void getResolvablesToInsDel ( const ResPool pool_r,
56                                     PoolItemList & dellist_r,
57                                     PoolItemList & instlist_r,
58                                     PoolItemList & srclist_r );
59
60
61     public:
62       /** Ctor. */
63       TargetImpl(const Pathname & root_r = "/");
64       /** Dtor. */
65       virtual ~TargetImpl();
66
67       /** Null implementation */
68       static TargetImpl_Ptr nullimpl();
69
70     public:
71
72       /** All resolvables in the target. */
73       const ResStore & resolvables();
74
75       /** Commit changes in the pool
76           media = 0 means any/all medias
77           media > 0 means limit commits to this media */
78       void commit( ResPool pool_r, unsigned int medianr, PoolItemList & errors_r, PoolItemList & remaining_r, PoolItemList & srcremaining_r );
79
80 #ifndef STORAGE_DISABLED
81       /** enables the storage target */
82       bool isStorageEnabled() const;
83       void enableStorage(const Pathname &root_r);
84 #endif
85
86       /** Commit ordered changes
87           return uncommitted ones (due to error) */
88       PoolItemList commit( const PoolItemList & items_r );
89
90       /** Overload to realize stream output. */
91       virtual std::ostream & dumpOn( std::ostream & str ) const
92       { return str << "TargetImpl"; }
93
94       /** The RPM database */
95       rpm::RpmDb & rpm();
96
97       /** If the package is installed and provides the file
98           Needed to evaluate split provides during Resolver::Upgrade() */
99       bool providesFile (const std::string & path_str, const std::string & name_str) const;
100
101       /** Return the resolvable which provides path_str (rpm -qf)
102           return NULL if no resolvable provides this file  */
103       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
104
105     protected:
106       /** All resolvables provided by the target. */
107       ResStore _store;
108       /** Path to the target */
109       Pathname _root;
110       /** RPM database */
111       rpm::RpmDb _rpm;
112 #ifndef STORAGE_DISABLED
113       zypp::storage::PersistentStorage _storage;
114 #endif
115     private:
116       /** Null implementation */
117       static TargetImpl_Ptr _nullimpl;
118       
119       /** wrapper with callback around getPlainRpm */
120       Pathname getRpmFile(Package::constPtr package);
121     };
122     ///////////////////////////////////////////////////////////////////
123
124     /** \relates TargetImpl Stream output */
125     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
126     { return obj.dumpOn( str ); }
127
128     /////////////////////////////////////////////////////////////////
129   } // namespace target
130   ///////////////////////////////////////////////////////////////////
131   /////////////////////////////////////////////////////////////////
132 } // namespace zypp
133 ///////////////////////////////////////////////////////////////////
134 #endif // ZYPP_TARGET_TARGETIMPL_H