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