- Prevent deselected or deleted items from being re-selected due to
[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 #include "zypp/target/RequestedLocalesFile.h"
32 #include "zypp/target/SoftLocksFile.h"
33
34 ///////////////////////////////////////////////////////////////////
35 namespace zypp
36 { /////////////////////////////////////////////////////////////////
37   ///////////////////////////////////////////////////////////////////
38   namespace target
39   { /////////////////////////////////////////////////////////////////
40
41     DEFINE_PTR_TYPE(TargetImpl);
42
43     ///////////////////////////////////////////////////////////////////
44     //
45     //  CLASS NAME : TargetImpl
46     //
47     /** Base class for concrete Target implementations.
48      *
49      * Constructed by \ref TargetFactory. Public access via \ref Target
50      * interface.
51     */
52     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
53     {
54       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
55
56     public:
57       /** list of pool items  */
58       typedef std::list<PoolItem> PoolItemList;
59
60       /** set of pool items  */
61       typedef std::set<PoolItem> PoolItemSet;
62
63     public:
64       /** Ctor. */
65       TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
66       /** Dtor. */
67       virtual ~TargetImpl();
68
69       /** Null implementation */
70       static TargetImpl_Ptr nullimpl();
71
72       void load();
73
74       void unload();
75
76       void clearCache();
77
78       void buildCache();
79
80     public:
81
82       /** The root set for this target */
83       Pathname root() const
84       { return _root; }
85
86       /** The directory to store things. */
87       Pathname home() const
88       { return _root / "/var/lib/zypp"; }
89
90       /** Commit changes in the pool */
91       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
92
93       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
94                                   PoolItemList & errors_r,
95                                   PoolItemList & remaining_r,
96                                   PoolItemList & srcremaining_r,
97                                   bool dry_run = false )
98       {
99         ZYppCommitPolicy policy;
100         policy.restrictToMedia( medianr ).dryRun( dry_run );
101         ZYppCommitResult res = commit( pool_r, policy );
102         errors_r.swap( res._errors );
103         remaining_r.swap( res._remaining );
104         srcremaining_r.swap( res._srcremaining );
105         return res._result;
106       }
107
108       /** Commit ordered changes
109        *  @param pool_r only needed for #160792
110        *  @return uncommitted ones (due to error)
111        */
112       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
113
114       /** Install a source package on the Target. */
115       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
116
117       /** Overload to realize stream output. */
118       virtual std::ostream & dumpOn( std::ostream & str ) const
119       {
120         return str << "TargetImpl";
121       }
122
123       /** The RPM database */
124       rpm::RpmDb & rpm();
125
126       /** If the package is installed and provides the file
127       Needed to evaluate split provides during Resolver::Upgrade() */
128       bool providesFile (const std::string & path_str, const std::string & name_str) const;
129
130       /** Return name of package owning \a path_str
131        * or empty string if no installed package owns \a path_str. */
132       std::string whoOwnsFile (const std::string & path_str) const
133       { return _rpm.whoOwnsFile (path_str); }
134
135       /** Set the log file for target */
136       bool setInstallationLogfile(const Pathname & path_r);
137
138       /** return the last modification date of the target */
139       Date timestamp() const;
140
141       /** The targets distribution release string.
142        * \code
143        *   openSUSE 10.3 (i586)
144        * \endcode
145        */
146       std::string release() const;
147
148     protected:
149       /** Path to the target */
150       Pathname _root;
151       /** RPM database */
152       rpm::RpmDb _rpm;
153       /** Requested Locales database */
154       RequestedLocalesFile _requestedLocalesFile;
155       /** Soft-locks database */
156       SoftLocksFile _softLocksFile;
157     private:
158       /** Null implementation */
159       static TargetImpl_Ptr _nullimpl;
160     };
161     ///////////////////////////////////////////////////////////////////
162
163     /** \relates TargetImpl Stream output */
164     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
165     {
166       return obj.dumpOn( str );
167     }
168
169     /////////////////////////////////////////////////////////////////
170   } // namespace target
171   ///////////////////////////////////////////////////////////////////
172   /////////////////////////////////////////////////////////////////
173 } // namespace zypp
174 ///////////////////////////////////////////////////////////////////
175 #endif // ZYPP_TARGET_TARGETIMPL_H