libzypp  10.5.0
TargetImpl.h
Go to the documentation of this file.
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 home( _root ); }
00122 
00123       static Pathname home( const Pathname & root_r )
00124       { return root_r / "/var/lib/zypp"; }
00125 
00127       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
00128 
00130       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
00131 
00133       virtual std::ostream & dumpOn( std::ostream & str ) const
00134       {
00135         return str << "TargetImpl";
00136       }
00137 
00139       rpm::RpmDb & rpm();
00140 
00143       bool providesFile (const std::string & path_str, const std::string & name_str) const;
00144 
00147       std::string whoOwnsFile (const std::string & path_str) const
00148       { return _rpm.whoOwnsFile (path_str); }
00149 
00151       Date timestamp() const;
00152 
00154       Product::constPtr baseProduct() const;
00155 
00157       LocaleSet requestedLocales() const
00158       { return _requestedLocalesFile.locales(); }
00160       static LocaleSet requestedLocales( const Pathname & root_r );
00161 
00163       std::string targetDistribution() const;
00165       static std::string targetDistribution( const Pathname & root_r );
00166 
00168       std::string targetDistributionRelease() const;
00170       static std::string targetDistributionRelease( const Pathname & root_r );
00171 
00173       Target::DistributionLabel distributionLabel() const;
00175       static Target::DistributionLabel distributionLabel( const Pathname & root_r );
00176 
00178       std::string distributionVersion() const;
00180       static std::string distributionVersion( const Pathname & root_r );
00181 
00183       std::string distributionFlavor() const;
00185       static std::string distributionFlavor( const Pathname & root_r );
00186 
00188       std::string anonymousUniqueId() const;
00190       static std::string anonymousUniqueId( const Pathname & root_r );
00191 
00192     private:
00194       void commit( const ZYppCommitPolicy & policy_r,
00195                    CommitPackageCache & packageCache_r,
00196                    ZYppCommitResult & result_r );
00197 
00198     protected:
00200       Pathname _root;
00202       rpm::RpmDb _rpm;
00204       RequestedLocalesFile _requestedLocalesFile;
00206       SoftLocksFile _softLocksFile;
00208       HardLocksFile _hardLocksFile;
00210       mutable std::string _distributionVersion;
00211 
00212     private:
00214       static TargetImpl_Ptr _nullimpl;
00215     };
00217 
00219     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
00220     {
00221       return obj.dumpOn( str );
00222     }
00223 
00225   } // namespace target
00228 } // namespace zypp
00230 #endif // ZYPP_TARGET_TARGETIMPL_H