RepoManager.h
Go to the documentation of this file.00001
00002
00003
00004
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
00054 struct RepoManagerOptions
00055 {
00067 RepoManagerOptions( const Pathname & root_r = Pathname() );
00068
00078 static RepoManagerOptions makeTestSetup( const Pathname & root_r );
00079
00080 Pathname repoCachePath;
00081 Pathname repoRawCachePath;
00082 Pathname repoSolvCachePath;
00083 Pathname repoPackagesCachePath;
00084 Pathname knownReposPath;
00085 Pathname knownServicesPath;
00086 bool probe;
00097 std::string servicesTargetDistro;
00098
00100 Pathname rootDir;
00101
00102
00103
00104
00105 Pathname pluginsPath() const;
00106 };
00107
00108
00109
00114 class RepoManager
00115 {
00116 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00117
00118 public:
00120 class Impl;
00121
00123 typedef std::set<ServiceInfo> ServiceSet;
00124 typedef ServiceSet::const_iterator ServiceConstIterator;
00125 typedef ServiceSet::size_type ServiceSizeType;
00126
00128 typedef std::set<RepoInfo> RepoSet;
00129 typedef RepoSet::const_iterator RepoConstIterator;
00130 typedef RepoSet::size_type RepoSizeType;
00131
00132 public:
00133 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
00135 ~RepoManager();
00136
00137 enum RawMetadataRefreshPolicy
00138 {
00139 RefreshIfNeeded,
00140 RefreshForced,
00141 RefreshIfNeededIgnoreDelay
00142 };
00143
00144 enum CacheBuildPolicy
00145 {
00146 BuildIfNeeded,
00147 BuildForced
00148 };
00149
00150 enum RepoRemovePolicy
00151 {
00152
00153 };
00154
00162 bool repoEmpty() const;
00163 RepoSizeType repoSize() const;
00164 RepoConstIterator repoBegin() const;
00165 RepoConstIterator repoEnd() const;
00166
00168 std::list<RepoInfo> knownRepositories() const
00169 { return std::list<RepoInfo>(repoBegin(),repoEnd()); }
00170
00172 RepoInfo getRepo( const std::string & alias ) const;
00174 RepoInfo getRepo( const RepoInfo & info_r ) const
00175 { return getRepo( info_r.alias() ); }
00176
00178 bool hasRepo( const std::string & alias ) const;
00180 bool hasRepo( const RepoInfo & info_r ) const
00181 { return hasRepo( info_r.alias() ); }
00182
00186 static std::string makeStupidAlias( const Url & url_r = Url() );
00188
00192 RepoStatus metadataStatus( const RepoInfo &info ) const;
00193
00197 enum RefreshCheckStatus {
00198 REFRESH_NEEDED,
00199 REPO_UP_TO_DATE,
00200 REPO_CHECK_DELAYED
00201 };
00202
00257 RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
00258 const Url &url,
00259 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
00260
00271 Pathname metadataPath( const RepoInfo &info ) const;
00272
00273
00284 Pathname packagesPath( const RepoInfo &info ) const;
00285
00286
00301 void refreshMetadata( const RepoInfo &info,
00302 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
00303 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00304
00313 void cleanMetadata( const RepoInfo &info,
00314 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00315
00324 void cleanPackages( const RepoInfo &info,
00325 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00326
00330 RepoStatus cacheStatus( const RepoInfo &info ) const;
00331
00350 void buildCache( const RepoInfo &info,
00351 CacheBuildPolicy policy = BuildIfNeeded,
00352 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00353
00366 void cleanCache( const RepoInfo &info,
00367 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00368
00374 bool isCached( const RepoInfo &info ) const;
00375
00376
00386 void loadFromCache( const RepoInfo &info,
00387 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00388
00396 void cleanCacheDirGarbage( const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00397
00405 repo::RepoType probe( const Url & url, const Pathname & path ) const;
00409 repo::RepoType probe( const Url & url ) const;
00410
00411
00426 void addRepository( const RepoInfo &info,
00427 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00428
00441 void addRepositories( const Url &url,
00442 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00448 void removeRepository( const RepoInfo & info,
00449 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00450
00460 void modifyRepository( const std::string &alias,
00461 const RepoInfo & newinfo,
00462 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00464 void modifyRepository( const RepoInfo & newinfo,
00465 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
00466 { modifyRepository( newinfo.alias(), newinfo, progressrcv ); }
00467
00481 RepoInfo getRepositoryInfo( const std::string &alias,
00482 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00483
00503 RepoInfo getRepositoryInfo( const Url & url,
00504 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
00505 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
00506
00507
00520 bool serviceEmpty() const;
00521
00527 ServiceSizeType serviceSize() const;
00528
00534 ServiceConstIterator serviceBegin() const;
00535
00540 ServiceConstIterator serviceEnd() const;
00541
00543 std::list<ServiceInfo> knownServices() const
00544 { return std::list<ServiceInfo>(serviceBegin(),serviceEnd()); }
00545
00552 ServiceInfo getService( const std::string & alias ) const;
00553
00555 bool hasService( const std::string & alias ) const;
00557
00561 repo::ServiceType probeService( const Url &url ) const;
00562
00571 void addService( const std::string & alias, const Url& url );
00572
00580 void addService( const ServiceInfo & service );
00581
00590 void removeService( const std::string & alias );
00592 void removeService( const ServiceInfo & service );
00593
00594
00600 void refreshServices();
00601
00610 void refreshService( const std::string & alias );
00612 void refreshService( const ServiceInfo & service );
00613
00630 void modifyService( const std::string & oldAlias, const ServiceInfo & service );
00632 void modifyService( const ServiceInfo & service )
00633 { modifyService( service.alias(), service ); }
00634
00635 private:
00639 struct MatchServiceAlias
00640 {
00641 public:
00642 MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
00643 bool operator()( const RepoInfo & info ) const
00644 { return info.service() == alias; }
00645 private:
00646 std::string alias;
00647 };
00648
00649 public:
00650
00683 template<typename OutputIterator>
00684 void getRepositoriesInService( const std::string & alias,
00685 OutputIterator out ) const
00686 {
00687 MatchServiceAlias filter(alias);
00688
00689 std::copy( boost::make_filter_iterator( filter, repoBegin(), repoEnd() ),
00690 boost::make_filter_iterator( filter, repoEnd(), repoEnd() ),
00691 out);
00692 }
00693
00694 protected:
00695 RepoStatus rawMetadataStatus( const RepoInfo &info );
00696 void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
00697
00702 void touchIndexFile(const RepoInfo & info);
00703
00704 public:
00705
00706 private:
00708 RWCOW_pointer<Impl> _pimpl;
00709 };
00711
00713 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
00714
00716 }
00718 #endif // ZYPP2_REPOMANAGER_H