Fix failed package download due to unkown repository type (bnc #386386)
[platform/upstream/libzypp.git] / zypp / RepoStatus.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoStatus.h
10  *
11 */
12 #ifndef ZYPP2_REPOSTATUS_H
13 #define ZYPP2_REPOSTATUS_H
14
15 #include <iosfwd>
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/CheckSum.h"
18 #include "zypp/Date.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   ///////////////////////////////////////////////////////////////////
25   //
26   //    CLASS NAME : RepoStatus
27   //
28   /**
29    * \short Local facts about a repository
30    * This class represents the status of a
31    * repository on the system.
32    *
33    * Anything that is not provided on the metadata
34    * files, like the timestamp of the downloaded
35    * metadata, and its checksum.
36    */
37   class RepoStatus
38   {
39     friend std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
40
41   public:
42     
43     /**
44      * reads the status from a file which contains the
45      * checksum and timestamp in each line.
46      *
47      * \throws Exception If the file is not valid or accessible
48      */
49     static RepoStatus fromCookieFile( const Pathname &path );
50   
51     /**
52      * save the status information to a cookie file
53      * \throws Exception if the file can't be saved
54      */
55     void saveToCookieFile( const Pathname &path ) const;
56
57     /**
58      * Checksum of the repository.
59      * Usually the checksum of the index, but any
60      * checksum that changes when the repository changes
61      * in any way is sufficient.
62      */
63     std::string checksum() const;
64     
65     /**
66      * timestamp of the repository. If the repository
67      * changes, it has to be updated as well with the
68      * new timestamp.
69      */
70     Date timestamp() const;
71     
72     /**
73      * \short Is the status empty?
74      *
75      * An empty status means that the status
76      * was not calculated.
77      */
78     bool empty() const;
79
80     /**
81      * set the repository checksum \see checksum
82      * \param checksum
83      */
84     RepoStatus & setChecksum( const std::string &checksum );
85     
86     /**
87      * set the repository timestamp \see timestamp
88      * \param timestamp
89      */
90     RepoStatus & setTimestamp( const Date &timestamp );
91
92     /** Implementation  */
93     class Impl;
94
95   public:
96     /** Default ctor */
97     RepoStatus();
98     
99     /**
100      * \short Status from a single file
101      * As most repository state is represented
102      * by the status of the index file, you can
103      * construct the status from a file.
104      *
105      * \note construct from a non existing
106      * file will result in an empty status
107      */
108     RepoStatus( const Pathname &file );
109     
110     /** Dtor */
111     ~RepoStatus();
112
113   public:
114
115   private:
116     /** Pointer to implementation */
117     RWCOW_pointer<Impl> _pimpl;
118   };
119   ///////////////////////////////////////////////////////////////////
120
121   /** \relates RepoStatus Stream output */
122   std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
123
124   /**
125    * combines 2 repostatus with a checksum based on both
126    * checksums and the newest timestamp
127    */
128   RepoStatus operator&&( const RepoStatus &lhs, const RepoStatus &rhs );
129
130   /////////////////////////////////////////////////////////////////
131 } // namespace zypp
132 ///////////////////////////////////////////////////////////////////
133 #endif // ZYPP2_REPOSTATUS_H