add mkdir for services and modifyServices, which is used during refresh
[platform/upstream/libzypp.git] / zypp / RepoManager.h
index e7ca0d1..cfcfa1c 100644 (file)
 #include <list>
 
 #include "zypp/base/PtrTypes.h"
-//#include "zypp/base/ReferenceCounted.h"
-//#include "zypp/base/NonCopyable.h"
 #include "zypp/Pathname.h"
 #include "zypp/ZConfig.h"
-#include "zypp/Repository.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/repo/RepoException.h"
 #include "zypp/repo/RepoType.h"
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
+  class Service; //predef
 
    /**
     * Parses \a repo_file and returns a list of \ref RepoInfo objects
     * corresponding to repositories found within the file.
-    * 
+    *
     * \param repo_file Valid URL of the repo file.
     * \return found list<RepoInfo>
     *
@@ -50,13 +48,41 @@ namespace zypp
    */
   struct RepoManagerOptions
   {
-    RepoManagerOptions();
-    
+    /** Default ctor following \ref ZConfig global settings.
+     * If an optional \c root_r directory is given, all paths  will
+     * be prefixed accordingly.
+     * \code
+     *    root_r\repoCachePath
+     *          \repoRawCachePath
+     *          \repoSolvCachePath
+     *          \repoPackagesCachePath
+     *          \knownReposPath
+     * \endcode
+     */
+    RepoManagerOptions( const Pathname & root_r = Pathname() );
+
+    /** Test setup adjusting all paths to be located below one \c root_r directory.
+     * \code
+     *    root_r\          - repoCachePath
+     *          \raw       - repoRawCachePath
+     *          \solv      - repoSolvCachePath
+     *          \packages  - repoPackagesCachePath
+     *          \repos.d   - knownReposPath
+     * \endcode
+     */
+    static RepoManagerOptions makeTestSetup( const Pathname & root_r );
+
     Pathname repoCachePath;
     Pathname repoRawCachePath;
+    Pathname repoSolvCachePath;
+    Pathname repoPackagesCachePath;
     Pathname knownReposPath;
+    Pathname knownServicesPath;
+    bool probe;
   };
 
+
+
   /**
    * \short creates and provides information about known sources.
    *
@@ -69,26 +95,32 @@ namespace zypp
     /** Implementation  */
     class Impl;
 
+    /** service typedefs */
+    typedef std::set<Service> ServiceSet;
+    typedef ServiceSet::const_iterator ServiceConstIterator;
+    typedef ServiceSet::size_type ServiceSizeType;
+
   public:
    RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
    /** Dtor */
     ~RepoManager();
-    
+
     enum RawMetadataRefreshPolicy
     {
       RefreshIfNeeded,
-      RefreshForced
+      RefreshForced,
+      RefreshIfNeededIgnoreDelay
     };
-    
+
     enum CacheBuildPolicy
     {
       BuildIfNeeded,
       BuildForced
     };
-    
+
     enum RepoRemovePolicy
     {
-      
+
     };
 
    /**
@@ -107,6 +139,15 @@ namespace zypp
     RepoStatus metadataStatus( const RepoInfo &info ) const;
 
     /**
+     * Possibly return state of checkIfRefreshMEtadata function
+     */
+    enum RefreshCheckStatus {
+      REFRESH_NEEDED,  /**< refresh is needed */
+      REPO_UP_TO_DATE, /**< repository not changed */
+      REPO_CHECK_DELAYED     /**< refresh is delayed due to settings */
+    };
+
+    /**
      * Checks whether to refresh metadata for specified repository and url.
      * <p>
      * The need for refresh is evaluated according to the following conditions,
@@ -122,9 +163,9 @@ namespace zypp
      * This method checks the status against the specified url only. If more
      * baseurls are defined for in the RepoInfo, each one must be check
      * individually. Example:
-     * 
+     *
      * <code>
-     * 
+     *
      * RepoInfo info;
      * // try urls one by one
      * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
@@ -134,9 +175,9 @@ namespace zypp
      *   {
      *     // check whether to refresh metadata
      *     // if the check fails for this url, it throws, so another url will be checked
-     *     if (!checkIfToRefreshMetadata(info, *it, policy))
+     *     if (checkIfToRefreshMetadata(info, *it, policy)!=RepoInfo::REFRESH_NEEDED)
      *       return;
-     *     
+     *
      *     // do the actual refresh
      *   }
      *   catch (const Exception & e)
@@ -145,22 +186,51 @@ namespace zypp
      *     ERR << *it << " doesn't look good. Trying another url." << endl;
      *   }
      * } // for all urls
-     * 
+     *
      * handle("No more URLs.");
-     * 
+     *
      * </code>
-     * 
+     *
      * \param info
      * \param url
      * \param policy
+     * \return state of repository
+     * \see RefreshCheckStatus
      * \throws RepoUnknownTypeException
      * \throws repo::RepoNoAliasException if can't figure an alias
      * \throws Exception on unknown error
-     *  
+     *
      */
-    bool checkIfToRefreshMetadata( const RepoInfo &info,
+    RefreshCheckStatus checkIfToRefreshMetadata( const RepoInfo &info,
                                    const Url &url,
                                    RawMetadataRefreshPolicy policy = RefreshIfNeeded);
+
+    /**
+     * \short Path where the metadata is downloaded and kept
+     *
+     * Given a repoinfo, tells where \ref RepoManager will download
+     * and keep the raw metadata.
+     *
+     * \param info Repository information
+     *
+     * \throws repo::RepoNoAliasException if can't figure an alias
+     */
+    Pathname metadataPath( const RepoInfo &info ) const;
+
+
+    /**
+     * \short Path where the rpm packages are downloaded and kept
+     *
+     * Given a repoinfo, tells where \ref RepoProvidePackage will download
+     * and keep the .rpm files.
+     *
+     * \param info Repository information
+     *
+     * \throws repo::RepoNoAliasException if can't figure an alias
+     */
+    Pathname packagesPath( const RepoInfo &info ) const;
+
+
    /**
     * \short Refresh local raw cache
     *
@@ -173,12 +243,12 @@ namespace zypp
     * \throws repo::RepoNoAliasException if can't figure an alias
     * \throws repo::RepoUnknownTypeException if the metadata is unknown
     * \throws repo::RepoException if the repository is invalid
-    *         (no valid metadata found at any of baseurls) 
+    *         (no valid metadata found at any of baseurls)
     */
    void refreshMetadata( const RepoInfo &info,
                          RawMetadataRefreshPolicy policy = RefreshIfNeeded,
                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-   
+
    /**
     * \short Clean local metadata
     *
@@ -191,6 +261,17 @@ namespace zypp
                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
 
    /**
+    * \short Clean local package cache
+    *
+    * Empty local directory with downloaded packages
+    *
+    * \throws repo::RepoNoAliasException if can't figure an alias
+    * \throws Exception on unknown error.
+    */
+   void cleanPackages( const RepoInfo &info,
+                       const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
+
+   /**
     * \short Status of metadata cache
     */
     RepoStatus cacheStatus( const RepoInfo &info ) const;
@@ -204,7 +285,7 @@ namespace zypp
     *
     * \note the local metadata must be valid.
     *
-    * \throws repo::RepoNoAliasException if can't figure 
+    * \throws repo::RepoNoAliasException if can't figure
     *     an alias to look in cache
     * \throws repo::RepoMetadataException if the metadata
     *     is not enough to build a cache (empty, incorrect, or
@@ -231,16 +312,17 @@ namespace zypp
     */
    void cleanCache( const RepoInfo &info,
                     const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-   
+
    /**
     * \short Whether a repository exists in cache
     *
     * \param RepoInfo to be checked.
     */
     bool isCached( const RepoInfo &info ) const;
-   
-   /**
-    * \short Create a repository object from the cache data
+
+
+    /**
+    * \short Load resolvables into the pool
     *
     * Creating from cache requires that the repository is
     * refreshed (metadata downloaded) and cached
@@ -248,35 +330,22 @@ namespace zypp
     * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
     * \throw RepoNotCachedException When the source is not cached.
     */
-   Repository createFromCache( const RepoInfo &info,
-                               const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-
-   /**
-    * \short Create a repository object from raw metadata
-    *
-    * Creating from cache requires that the repository is
-    * refreshed (metadata downloaded)
-    *
-    * \throw Exception If there are errors parsing the
-    * raw metadata
-    */
-   Repository createFromMetadata( const RepoInfo &info,
-                                  const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-
+   void loadFromCache( const RepoInfo &info,
+                       const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
    /**
     * \short Probe repo metadata type.
     *
     * \todo FIXME Should this be private?
     */
    repo::RepoType probe( const Url &url ) const;
-   
-   
+
+
    /**
     * \short Adds a repository to the list of known repositories.
     *
-    * 
     *
-    * \throws repo::RepoAlreadyExistsException If the repo clash some 
+    *
+    * \throws repo::RepoAlreadyExistsException If the repo clash some
     *         unique attribute like alias
     * \throws RepoUnknownType If repository type can't be determined
     * \throws RepoException If the access to the url fails (while probing).
@@ -284,12 +353,12 @@ namespace zypp
     */
    void addRepository( const RepoInfo &info,
                        const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-   
+
    /**
     * \short Adds repositores from a repo file to the list of known repositories.
     * \param url Url of the repo file
-    * 
-    * \throws repo::RepoAlreadyExistsException If the repo clash some 
+    *
+    * \throws repo::RepoAlreadyExistsException If the repo clash some
     * unique attribute like alias
     *
     * \throws RepoAlreadyExistsException
@@ -308,10 +377,12 @@ namespace zypp
      */
     void removeRepository( const RepoInfo & info,
                            const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-    
+
     /**
      * \short Modify repository attributes
      *
+     * \throws RepoAlreadyExistsException if the alias specified in newinfo
+     *         is already used by another repository
      * \throws RepoNotFoundException If no repo match
      * \throws ParseException If the file parsing fails
      * \throws Exception On other errors.
@@ -335,7 +406,7 @@ namespace zypp
      */
     RepoInfo getRepositoryInfo( const std::string &alias,
                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
-    
+
     /**
      * \short Find repository info by URL.
      *
@@ -359,13 +430,35 @@ namespace zypp
                                 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
                                 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
 
+    void addService( const std::string& name, const Url& url );
+
+    void removeService( const std::string& name );
+
+    bool serviceEmpty() const;
+
+    ServiceSizeType serviceSize() const;
+
+    ServiceConstIterator serviceBegin() const;
+
+    ServiceConstIterator serviceEnd() const;
+
+    const Service& getService( const std::string& name ) const;
+
+    void refreshServices();
+
+    /**
+     * modify service, except name change
+     * ( you need remove and add if you want change name )
+     */
+    void modifyService(const Service& service) const;
+
   protected:
     RepoStatus rawMetadataStatus( const RepoInfo &info );
-    RepoStatus cacheStatus( const RepoInfo &info );
-    
+    void setCacheStatus( const RepoInfo &info, const RepoStatus &status );
+
     /**
      * Update timestamp of repository index file for the specified repository \a info.
-     * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature. 
+     * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
      */
     void touchIndexFile(const RepoInfo & info);