no feedback, tests passes, go on
[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 #include <list>
17 #include <set>
18
19 #include "zypp/base/ReferenceCounted.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22 #include "zypp/ResStore.h"
23 #include "zypp/PoolItem.h"
24
25 #include "zypp/Pathname.h"
26 #include "zypp/media/MediaAccess.h"
27 #include "zypp/Target.h"
28 #include "zypp/target/rpm/RpmDb.h"
29 #include "zypp/target/store/PersistentStorage.h"
30 #include "zypp/target/TargetException.h"
31
32 ///////////////////////////////////////////////////////////////////
33 namespace zypp
34 { /////////////////////////////////////////////////////////////////
35   ///////////////////////////////////////////////////////////////////
36   namespace target
37   { /////////////////////////////////////////////////////////////////
38
39     DEFINE_PTR_TYPE(TargetImpl);
40
41     ///////////////////////////////////////////////////////////////////
42     //
43     //  CLASS NAME : TargetImpl
44     //
45     /** Base class for concrete Target implementations.
46      *
47      * Constructed by \ref TargetFactory. Public access via \ref Target
48      * interface.
49     */
50     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
51     {
52       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
53
54     public:
55       /** list of pool items  */
56       typedef std::list<PoolItem_Ref> PoolItemList;
57
58       /** set of pool items  */
59       typedef std::set<PoolItem_Ref> PoolItemSet;
60
61     public:
62       /** JUST FOR TESTSUITE */
63       /** Sort according to prereqs and media numbers */
64       void getResolvablesToInsDel ( const ResPool pool_r,
65                                     PoolItemList & dellist_r,
66                                     PoolItemList & instlist_r,
67                                     PoolItemList & srclist_r ) const;
68
69
70     public:
71       /** Ctor. */
72       TargetImpl(const Pathname & root_r = "/");
73       /** Dtor. */
74       virtual ~TargetImpl();
75
76       /** Null implementation */
77       static TargetImpl_Ptr nullimpl();
78
79     public:
80
81       /** All resolvables in the target. */
82       const ResStore & resolvables();
83
84       /** The root set for this target */
85       Pathname root() const;
86
87       /** Commit changes in the pool
88           media = 0 means any/all medias
89           media > 0 means limit commits to this media */
90       int commit( ResPool pool_r, unsigned int medianr, PoolItemList & errors_r, PoolItemList & remaining_r, PoolItemList & srcremaining_r, bool dry_run = false );
91
92       /** enables the storage target */
93       bool isStorageEnabled() const;
94       void enableStorage(const Pathname &root_r);
95
96       /** Commit ordered changes
97           return uncommitted ones (due to error) */
98       PoolItemList commit( const PoolItemList & items_r, bool dry_run = false );
99
100       /** Overload to realize stream output. */
101       virtual std::ostream & dumpOn( std::ostream & str ) const
102       { return str << "TargetImpl"; }
103
104       /** The RPM database */
105       rpm::RpmDb & rpm();
106
107       /** If the package is installed and provides the file
108           Needed to evaluate split provides during Resolver::Upgrade() */
109       bool providesFile (const std::string & path_str, const std::string & name_str) const;
110
111       /** Return the resolvable which provides path_str (rpm -qf)
112           return NULL if no resolvable provides this file  */
113       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
114
115       /** Set the log file for target */
116       bool setInstallationLogfile(const Pathname & path_r);
117
118     protected:
119       /** All resolvables provided by the target. */
120       ResStore _store;
121       /** Path to the target */
122       Pathname _root;
123       /** RPM database */
124       rpm::RpmDb _rpm;
125 #ifndef STORAGE_DISABLED
126       zypp::storage::PersistentStorage _storage;
127       bool _storage_enabled;
128 #endif
129     private:
130       /** Null implementation */
131       static TargetImpl_Ptr _nullimpl;
132     };
133     ///////////////////////////////////////////////////////////////////
134
135     /** \relates TargetImpl Stream output */
136     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
137     { return obj.dumpOn( str ); }
138
139     /////////////////////////////////////////////////////////////////
140   } // namespace target
141   ///////////////////////////////////////////////////////////////////
142   /////////////////////////////////////////////////////////////////
143 } // namespace zypp
144 ///////////////////////////////////////////////////////////////////
145 #endif // ZYPP_TARGET_TARGETIMPL_H