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     bool probe;
00095     std::string servicesTargetDistro;
00096 
00098     Pathname rootDir;
00099   };
00100 
00101 
00102 
00107   class RepoManager
00108   {
00109     friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00110 
00111   public:
00113     class Impl;
00114 
00116     typedef std::set<ServiceInfo> ServiceSet;
00117     typedef ServiceSet::const_iterator ServiceConstIterator;
00118     typedef ServiceSet::size_type ServiceSizeType;
00119 
00121     typedef std::set<RepoInfo> RepoSet;
00122     typedef RepoSet::const_iterator RepoConstIterator;
00123     typedef RepoSet::size_type RepoSizeType;
00124 
00125   public:
00126    RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
00128     ~RepoManager();
00129 
00130     enum RawMetadataRefreshPolicy
00131     {
00132       RefreshIfNeeded,
00133       RefreshForced,
00134       RefreshIfNeededIgnoreDelay
00135     };
00136 
00137     enum CacheBuildPolicy
00138     {
00139       BuildIfNeeded,
00140       BuildForced
00141     };
00142 
00143     enum RepoRemovePolicy
00144     {
00145 
00146     };
00147 
00155     bool repoEmpty() const;
00156     RepoSizeType repoSize() const;
00157     RepoConstIterator repoBegin() const;
00158     RepoConstIterator repoEnd() const;
00159 
00161     std::list<RepoInfo> knownRepositories() const
00162     { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
00163 
00165     RepoInfo getRepo( const std::string & alias ) const;
00167     RepoInfo getRepo( const RepoInfo & info_r ) const
00168     { return getRepo( info_r.alias() ); }
00169 
00171     bool hasRepo( const std::string & alias ) const;
00173     bool hasRepo( const RepoInfo & info_r ) const
00174     { return hasRepo( info_r.alias() ); }
00175 
00179     static std::string makeStupidAlias( const Url & url_r = Url() );
00181 
00185     RepoStatus metadataStatus( const RepoInfo &info ) const;
00186 
00190     enum RefreshCheckStatus {
00191       REFRESH_NEEDED,  
00192       REPO_UP_TO_DATE, 
00193       REPO_CHECK_DELAYED     
00194     };
00195 
00250     RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
00251                                    const Url &url,
00252                                    RawMetadataRefreshPolicy policy = RefreshIfNeeded);
00253 
00264     Pathname metadataPath( const RepoInfo &info ) const;
00265 
00266 
00277     Pathname packagesPath( const RepoInfo &info ) const;
00278 
00279 
00294    void refreshMetadata( const RepoInfo &info,
00295                          RawMetadataRefreshPolicy policy = RefreshIfNeeded,
00296                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00297 
00306    void cleanMetadata( const RepoInfo &info,
00307                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00308 
00317    void cleanPackages( const RepoInfo &info,
00318                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00319 
00323     RepoStatus cacheStatus( const RepoInfo &info ) const;
00324 
00343    void buildCache( const RepoInfo &info,
00344                     CacheBuildPolicy policy = BuildIfNeeded,
00345                     const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00346 
00359    void cleanCache( const RepoInfo &info,
00360                     const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00361 
00367     bool isCached( const RepoInfo &info ) const;
00368 
00369 
00379    void loadFromCache( const RepoInfo &info,
00380                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00381 
00389    void cleanCacheDirGarbage( const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00390 
00398    repo::RepoType probe( const Url & url, const Pathname & path ) const;
00402    repo::RepoType probe( const Url & url ) const;
00403 
00404 
00419    void addRepository( const RepoInfo &info,
00420                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00421 
00434     void addRepositories( const Url &url,
00435                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00441     void removeRepository( const RepoInfo & info,
00442                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00443 
00453     void modifyRepository( const std::string &alias,
00454                            const RepoInfo & newinfo,
00455                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00457     void modifyRepository( const RepoInfo & newinfo,
00458                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
00459     { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
00460 
00474     RepoInfo getRepositoryInfo( const std::string &alias,
00475                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00476 
00496     RepoInfo getRepositoryInfo( const Url & url,
00497                                 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
00498                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00499 
00500 
00513     bool serviceEmpty() const;
00514 
00520     ServiceSizeType serviceSize() const;
00521 
00527     ServiceConstIterator serviceBegin() const;
00528 
00533     ServiceConstIterator serviceEnd() const;
00534 
00536     std::list<ServiceInfo> knownServices() const
00537     { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
00538 
00545     ServiceInfo getService( const std::string & alias ) const;
00546 
00548     bool hasService( const std::string & alias ) const;
00550 
00554     repo::ServiceType probeService( const Url &url ) const;
00555 
00564     void addService( const std::string & alias, const Url& url );
00565 
00573     void addService( const ServiceInfo & service );
00574 
00583     void removeService( const std::string & alias );
00585     void removeService( const ServiceInfo & service );
00586 
00587 
00593     void refreshServices();
00594 
00603     void refreshService( const std::string & alias );
00605     void refreshService( const ServiceInfo & service );
00606 
00623     void modifyService( const std::string & oldAlias, const ServiceInfo & service );
00625     void modifyService( const ServiceInfo & service )
00626     { modifyService( service.alias(), service ); }
00627 
00628   private:
00632     struct MatchServiceAlias
00633     {
00634       public:
00635         MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
00636         bool operator()( const RepoInfo & info ) const
00637         { return info.service() == alias; }
00638       private:
00639         std::string alias;
00640     };
00641 
00642   public:
00643 
00676     template<typename OutputIterator>
00677     void getRepositoriesInService( const std::string & alias,
00678                                    OutputIterator out ) const
00679     {
00680       MatchServiceAlias filter(alias);
00681 
00682       std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
00683                  boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
00684                  out);
00685     }
00686 
00687   protected:
00688     RepoStatus rawMetadataStatus( const RepoInfo &info );
00689     void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
00690 
00695     void touchIndexFile(const RepoInfo & info);
00696 
00697   public:
00698 
00699   private:
00701     RWCOW_pointer<Impl> _pimpl;
00702   };
00704 
00706   std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00707 
00709 } // namespace zypp
00711 #endif // ZYPP2_REPOMANAGER_H
Generated on Fri Mar 2 09:45:53 2012 for libzypp by  doxygen 1.6.3