- Implement a more efficient rpm cache based on micha and coolo's ideas
[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/DefaultFalseBool.h"
22 #include "zypp/base/PtrTypes.h"
23 #include "zypp/PoolItem.h"
24 #include "zypp/ZYppCommit.h"
25
26 #include "zypp/Pathname.h"
27 #include "zypp/media/MediaAccess.h"
28 #include "zypp/Target.h"
29 #include "zypp/target/rpm/RpmDb.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> PoolItemList;
57
58       /** set of pool items  */
59       typedef std::set<PoolItem> PoolItemSet;
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       void load();
71
72       void buildCache();
73       
74     public:
75
76       /** The root set for this target */
77       Pathname root() const;
78
79       /** Commit changes in the pool */
80       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
81
82       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
83                                   PoolItemList & errors_r,
84                                   PoolItemList & remaining_r,
85                                   PoolItemList & srcremaining_r,
86                                   bool dry_run = false )
87       {
88         ZYppCommitPolicy policy;
89         policy.restrictToMedia( medianr ).dryRun( dry_run );
90         ZYppCommitResult res = commit( pool_r, policy );
91         errors_r.swap( res._errors );
92         remaining_r.swap( res._remaining );
93         srcremaining_r.swap( res._srcremaining );
94         return res._result;
95       }
96
97       /** Commit ordered changes
98        *  @param pool_r only needed for #160792
99        *  @return uncommitted ones (due to error)
100        */
101       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
102
103       /** Install a source package on the Target. */
104       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
105
106       /** Overload to realize stream output. */
107       virtual std::ostream & dumpOn( std::ostream & str ) const
108       {
109         return str << "TargetImpl";
110       }
111
112       /** The RPM database */
113       rpm::RpmDb & rpm();
114
115       /** If the package is installed and provides the file
116       Needed to evaluate split provides during Resolver::Upgrade() */
117       bool providesFile (const std::string & path_str, const std::string & name_str) const;
118
119       /** Return name of package owning \a path_str
120        * or empty string if no installed package owns \a path_str. */
121       std::string whoOwnsFile (const std::string & path_str) const
122       { return _rpm.whoOwnsFile (path_str); }
123
124       /** Set the log file for target */
125       bool setInstallationLogfile(const Pathname & path_r);
126
127       /** return the last modification date of the target */
128       Date timestamp() const;
129
130      /**
131       * reload the target in future calls if
132       * needed.
133       * note the loading can actually be delayed, but
134       * the next call to resolvables must reflect the
135       * status of the system.
136      */
137      void reset();
138
139     protected:
140       /** Path to the target */
141       Pathname _root;
142       /** RPM database */
143       rpm::RpmDb _rpm;
144     private:
145       /** Null implementation */
146       static TargetImpl_Ptr _nullimpl;
147     };
148     ///////////////////////////////////////////////////////////////////
149
150     /** \relates TargetImpl Stream output */
151     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
152     {
153       return obj.dumpOn( str );
154     }
155
156     /////////////////////////////////////////////////////////////////
157   } // namespace target
158   ///////////////////////////////////////////////////////////////////
159   /////////////////////////////////////////////////////////////////
160 } // namespace zypp
161 ///////////////////////////////////////////////////////////////////
162 #endif // ZYPP_TARGET_TARGETIMPL_H