libzypp  10.5.0
RepoManager.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_REPOMANAGER_H
00013 #define ZYPP_REPOMANAGER_H
00014 
00015 #include <iosfwd>
00016 #include <list>
00017 
00018 #include "zypp/base/PtrTypes.h"
00019 #include "zypp/base/Iterator.h"
00020 
00021 #include "zypp/Pathname.h"
00022 #include "zypp/ZConfig.h"
00023 #include "zypp/RepoInfo.h"
00024 #include "zypp/repo/RepoException.h"
00025 #include "zypp/repo/RepoType.h"
00026 #include "zypp/repo/ServiceType.h"
00027 #include "zypp/ServiceInfo.h"
00028 #include "zypp/RepoStatus.h"
00029 #include "zypp/ProgressData.h"
00030 
00032 namespace zypp
00033 { 
00034 
00046    std::list<RepoInfo> readRepoFile(const Url & repo_file);
00047 
00052   struct RepoManagerOptions
00053   {
00065     RepoManagerOptions( const Pathname & root_r = Pathname() );
00066 
00076     static RepoManagerOptions makeTestSetup( const Pathname & root_r );
00077 
00078     Pathname repoCachePath;
00079     Pathname repoRawCachePath;
00080     Pathname repoSolvCachePath;
00081     Pathname repoPackagesCachePath;
00082     Pathname knownReposPath;
00083     Pathname knownServicesPath;
00084     Pathname pluginsPath;
00085     bool probe;
00096     std::string servicesTargetDistro;
00097 
00099     Pathname rootDir;
00100   };
00101 
00102 
00103 
00108   class RepoManager
00109   {
00110     friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00111 
00112   public:
00114     class Impl;
00115 
00117     typedef std::set<ServiceInfo> ServiceSet;
00118     typedef ServiceSet::const_iterator ServiceConstIterator;
00119     typedef ServiceSet::size_type ServiceSizeType;
00120 
00122     typedef std::set<RepoInfo> RepoSet;
00123     typedef RepoSet::const_iterator RepoConstIterator;
00124     typedef RepoSet::size_type RepoSizeType;
00125 
00126   public:
00127    RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
00129     ~RepoManager();
00130 
00131     enum RawMetadataRefreshPolicy
00132     {
00133       RefreshIfNeeded,
00134       RefreshForced,
00135       RefreshIfNeededIgnoreDelay
00136     };
00137 
00138     enum CacheBuildPolicy
00139     {
00140       BuildIfNeeded,
00141       BuildForced
00142     };
00143 
00144     enum RepoRemovePolicy
00145     {
00146 
00147     };
00148 
00156     bool repoEmpty() const;
00157     RepoSizeType repoSize() const;
00158     RepoConstIterator repoBegin() const;
00159     RepoConstIterator repoEnd() const;
00160 
00162     std::list<RepoInfo> knownRepositories() const
00163     { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
00164 
00166     RepoInfo getRepo( const std::string & alias ) const;
00168     RepoInfo getRepo( const RepoInfo & info_r ) const
00169     { return getRepo( info_r.alias() ); }
00170 
00172     bool hasRepo( const std::string & alias ) const;
00174     bool hasRepo( const RepoInfo & info_r ) const
00175     { return hasRepo( info_r.alias() ); }
00176 
00180     static std::string makeStupidAlias( const Url & url_r = Url() );
00182 
00186     RepoStatus metadataStatus( const RepoInfo &info ) const;
00187 
00191     enum RefreshCheckStatus {
00192       REFRESH_NEEDED,  
00193       REPO_UP_TO_DATE, 
00194       REPO_CHECK_DELAYED     
00195     };
00196 
00251     RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
00252                                    const Url &url,
00253                                    RawMetadataRefreshPolicy policy = RefreshIfNeeded);
00254 
00265     Pathname metadataPath( const RepoInfo &info ) const;
00266 
00267 
00278     Pathname packagesPath( const RepoInfo &info ) const;
00279 
00280 
00295    void refreshMetadata( const RepoInfo &info,
00296                          RawMetadataRefreshPolicy policy = RefreshIfNeeded,
00297                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00298 
00307    void cleanMetadata( const RepoInfo &info,
00308                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00309 
00318    void cleanPackages( const RepoInfo &info,
00319                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00320 
00324     RepoStatus cacheStatus( const RepoInfo &info ) const;
00325 
00344    void buildCache( const RepoInfo &info,
00345                     CacheBuildPolicy policy = BuildIfNeeded,
00346                     const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00347 
00360    void cleanCache( const RepoInfo &info,
00361                     const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00362 
00368     bool isCached( const RepoInfo &info ) const;
00369 
00370 
00380    void loadFromCache( const RepoInfo &info,
00381                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00382 
00390    void cleanCacheDirGarbage( const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00391 
00399    repo::RepoType probe( const Url & url, const Pathname & path ) const;
00403    repo::RepoType probe( const Url & url ) const;
00404 
00405 
00420    void addRepository( const RepoInfo &info,
00421                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00422 
00435     void addRepositories( const Url &url,
00436                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00442     void removeRepository( const RepoInfo & info,
00443                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00444 
00454     void modifyRepository( const std::string &alias,
00455                            const RepoInfo & newinfo,
00456                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00458     void modifyRepository( const RepoInfo & newinfo,
00459                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
00460     { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
00461 
00475     RepoInfo getRepositoryInfo( const std::string &alias,
00476                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00477 
00497     RepoInfo getRepositoryInfo( const Url & url,
00498                                 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
00499                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00500 
00501 
00514     bool serviceEmpty() const;
00515 
00521     ServiceSizeType serviceSize() const;
00522 
00528     ServiceConstIterator serviceBegin() const;
00529 
00534     ServiceConstIterator serviceEnd() const;
00535 
00537     std::list<ServiceInfo> knownServices() const
00538     { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
00539 
00546     ServiceInfo getService( const std::string & alias ) const;
00547 
00549     bool hasService( const std::string & alias ) const;
00551 
00555     repo::ServiceType probeService( const Url &url ) const;
00556 
00565     void addService( const std::string & alias, const Url& url );
00566 
00574     void addService( const ServiceInfo & service );
00575 
00584     void removeService( const std::string & alias );
00586     void removeService( const ServiceInfo & service );
00587 
00588 
00594     void refreshServices();
00595 
00604     void refreshService( const std::string & alias );
00606     void refreshService( const ServiceInfo & service );
00607 
00624     void modifyService( const std::string & oldAlias, const ServiceInfo & service );
00626     void modifyService( const ServiceInfo & service )
00627     { modifyService( service.alias(), service ); }
00628 
00629   private:
00633     struct MatchServiceAlias
00634     {
00635       public:
00636         MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
00637         bool operator()( const RepoInfo & info ) const
00638         { return info.service() == alias; }
00639       private:
00640         std::string alias;
00641     };
00642 
00643   public:
00644 
00677     template<typename OutputIterator>
00678     void getRepositoriesInService( const std::string & alias,
00679                                    OutputIterator out ) const
00680     {
00681       MatchServiceAlias filter(alias);
00682 
00683       std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
00684                  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
00685                  out);
00686     }
00687 
00688   protected:
00689     RepoStatus rawMetadataStatus( const RepoInfo &info );
00690     void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
00691 
00696     void touchIndexFile(const RepoInfo & info);
00697 
00698   public:
00699 
00700   private:
00702     RWCOW_pointer<Impl> _pimpl;
00703   };
00705 
00707   std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00708 
00710 } // namespace zypp
00712 #endif // ZYPP2_REPOMANAGER_H