1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/TargetImpl.h
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
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/ResStore.h"
24 #include "zypp/PoolItem.h"
25 #include "zypp/ZYppCommit.h"
27 #include "zypp/Pathname.h"
28 #include "zypp/media/MediaAccess.h"
29 #include "zypp/Target.h"
30 #include "zypp/target/rpm/RpmDb.h"
31 #include "zypp/target/store/PersistentStorage.h"
32 #include "zypp/target/TargetException.h"
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 { /////////////////////////////////////////////////////////////////
41 DEFINE_PTR_TYPE(TargetImpl);
43 ///////////////////////////////////////////////////////////////////
45 // CLASS NAME : TargetImpl
47 /** Base class for concrete Target implementations.
49 * Constructed by \ref TargetFactory. Public access via \ref Target
52 class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
54 friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
57 /** list of pool items */
58 typedef std::list<PoolItem_Ref> PoolItemList;
60 /** set of pool items */
61 typedef std::set<PoolItem_Ref> PoolItemSet;
65 TargetImpl(const Pathname & root_r = "/");
67 virtual ~TargetImpl();
69 /** Null implementation */
70 static TargetImpl_Ptr nullimpl();
74 /** All resolvables in the target. */
75 const ResStore & resolvables();
78 * load resolvables of certain kind in the internal store
79 * and return a iterator
80 * successive calls will be faster as resolvables are cached-
82 ResStore::resfilter_const_iterator byKindBegin( const ResObject::Kind & kind_r ) const;
83 ResStore::resfilter_const_iterator byKindEnd( const ResObject::Kind & kind_r ) const;
85 /** The root set for this target */
86 Pathname root() const;
88 /** Commit changes in the pool */
89 ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
91 ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
92 PoolItemList & errors_r,
93 PoolItemList & remaining_r,
94 PoolItemList & srcremaining_r,
95 bool dry_run = false )
97 ZYppCommitPolicy policy;
98 policy.restrictToMedia( medianr ).dryRun( dry_run );
99 ZYppCommitResult res = commit( pool_r, policy );
100 errors_r.swap( res._errors );
101 remaining_r.swap( res._remaining );
102 srcremaining_r.swap( res._srcremaining );
106 /** enables the storage target */
107 bool isStorageEnabled() const;
108 void enableStorage(const Pathname &root_r);
110 /** Commit ordered changes
111 * @param pool_r only needed for #160792
112 * @return uncommitted ones (due to error)
114 PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
116 /** Install a source package on the Target. */
117 void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
119 /** Overload to realize stream output. */
120 virtual std::ostream & dumpOn( std::ostream & str ) const
122 return str << "TargetImpl";
125 /** The RPM database */
128 /** If the package is installed and provides the file
129 Needed to evaluate split provides during Resolver::Upgrade() */
130 bool providesFile (const std::string & path_str, const std::string & name_str) const;
132 /** Return the resolvable which provides path_str (rpm -qf)
133 return NULL if no resolvable provides this file */
134 ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
136 /** Set the log file for target */
137 bool setInstallationLogfile(const Pathname & path_r);
139 /** return the last modification date of the target */
140 Date timestamp() const;
143 * reload the target in future calls if
145 * note the loading can actually be delayed, but
146 * the next call to resolvables must reflect the
147 * status of the system.
152 void loadKindResolvables( const Resolvable::Kind kind );
153 /** All resolvables provided by the target. */
155 /** Path to the target */
159 #ifndef STORAGE_DISABLED
160 zypp::storage::PersistentStorage _storage;
161 bool _storage_enabled;
162 std::map< const Resolvable::Kind, DefaultFalseBool> _resstore_loaded;
165 /** Null implementation */
166 static TargetImpl_Ptr _nullimpl;
168 ///////////////////////////////////////////////////////////////////
170 /** \relates TargetImpl Stream output */
171 inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
173 return obj.dumpOn( str );
176 /////////////////////////////////////////////////////////////////
177 } // namespace target
178 ///////////////////////////////////////////////////////////////////
179 /////////////////////////////////////////////////////////////////
181 ///////////////////////////////////////////////////////////////////
182 #endif // ZYPP_TARGET_TARGETIMPL_H