00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_TARGET_TARGETIMPL_H 00013 #define ZYPP_TARGET_TARGETIMPL_H 00014 00015 #include <iosfwd> 00016 #include <set> 00017 00018 #include "zypp/base/ReferenceCounted.h" 00019 #include "zypp/base/NonCopyable.h" 00020 #include "zypp/base/PtrTypes.h" 00021 #include "zypp/PoolItem.h" 00022 #include "zypp/ZYppCommit.h" 00023 00024 #include "zypp/Pathname.h" 00025 #include "zypp/media/MediaAccess.h" 00026 #include "zypp/Target.h" 00027 #include "zypp/target/rpm/RpmDb.h" 00028 #include "zypp/target/TargetException.h" 00029 #include "zypp/target/RequestedLocalesFile.h" 00030 #include "zypp/target/SoftLocksFile.h" 00031 #include "zypp/target/HardLocksFile.h" 00032 00034 namespace zypp 00035 { 00036 00037 namespace target 00038 { 00039 00040 DEFINE_PTR_TYPE(TargetImpl); 00041 class CommitPackageCache; 00042 00044 // 00045 // CLASS NAME : TargetImpl 00046 // 00052 class TargetImpl : public base::ReferenceCounted, private base::NonCopyable 00053 { 00054 friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj ); 00055 00056 public: 00058 typedef std::list<PoolItem> PoolItemList; 00059 00061 typedef std::set<PoolItem> PoolItemSet; 00062 00063 public: 00065 TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false ); 00067 virtual ~TargetImpl(); 00068 00070 static TargetImpl_Ptr nullimpl(); 00071 00076 void createAnonymousId() const; 00077 00081 void createLastDistributionFlavorCache() const; 00082 00089 private: 00091 Pathname defaultSolvfilesPath() const; 00092 00094 Pathname solvfilesPath() const 00095 { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); } 00096 00098 bool solvfilesPathIsTemp() const 00099 { return ! _tmpSolvfilesPath.empty(); } 00100 00101 Pathname _tmpSolvfilesPath; 00102 00103 public: 00104 void load(); 00105 00106 void unload(); 00107 00108 void clearCache(); 00109 00110 void buildCache(); 00112 00113 public: 00114 00116 Pathname root() const 00117 { return _root; } 00118 00120 Pathname home() const 00121 { return _root / "/var/lib/zypp"; } 00122 00124 ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r ); 00125 00127 void installSrcPackage( const SrcPackage_constPtr & srcPackage_r ); 00128 00130 virtual std::ostream & dumpOn( std::ostream & str ) const 00131 { 00132 return str << "TargetImpl"; 00133 } 00134 00136 rpm::RpmDb & rpm(); 00137 00140 bool providesFile (const std::string & path_str, const std::string & name_str) const; 00141 00144 std::string whoOwnsFile (const std::string & path_str) const 00145 { return _rpm.whoOwnsFile (path_str); } 00146 00148 Date timestamp() const; 00149 00151 Product::constPtr baseProduct() const; 00152 00153 00155 std::string targetDistribution() const; 00157 static std::string targetDistribution( const Pathname & root_r ); 00158 00160 std::string targetDistributionRelease() const; 00162 static std::string targetDistributionRelease( const Pathname & root_r ); 00163 00165 Target::DistributionLabel distributionLabel() const; 00167 static Target::DistributionLabel distributionLabel( const Pathname & root_r ); 00168 00170 std::string distributionVersion() const; 00172 static std::string distributionVersion( const Pathname & root_r ); 00173 00175 std::string distributionFlavor() const; 00177 static std::string distributionFlavor( const Pathname & root_r ); 00178 00180 std::string anonymousUniqueId() const; 00182 static std::string anonymousUniqueId( const Pathname & root_r ); 00183 00184 private: 00186 void commit( const ZYppCommitPolicy & policy_r, 00187 CommitPackageCache & packageCache_r, 00188 ZYppCommitResult & result_r ); 00189 00190 protected: 00192 Pathname _root; 00194 rpm::RpmDb _rpm; 00196 RequestedLocalesFile _requestedLocalesFile; 00198 SoftLocksFile _softLocksFile; 00200 HardLocksFile _hardLocksFile; 00202 mutable std::string _distributionVersion; 00203 00204 private: 00206 static TargetImpl_Ptr _nullimpl; 00207 }; 00209 00211 inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj ) 00212 { 00213 return obj.dumpOn( str ); 00214 } 00215 00217 } // namespace target 00220 } // namespace zypp 00222 #endif // ZYPP_TARGET_TARGETIMPL_H