- A missing cookie file must not be treated as an error. Simply
[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      * \returns An empty \ref RepoStatus if the file does not
48      * exist or is not readable.
49      */
50     static RepoStatus fromCookieFile( const Pathname &path );
51
52     /**
53      * save the status information to a cookie file
54      * \throws Exception if the file can't be saved
55      */
56     void saveToCookieFile( const Pathname &path ) const;
57
58     /**
59      * Checksum of the repository.
60      * Usually the checksum of the index, but any
61      * checksum that changes when the repository changes
62      * in any way is sufficient.
63      */
64     std::string checksum() const;
65
66     /**
67      * timestamp of the repository. If the repository
68      * changes, it has to be updated as well with the
69      * new timestamp.
70      */
71     Date timestamp() const;
72
73     /**
74      * \short Is the status empty?
75      *
76      * An empty status means that the status
77      * was not calculated.
78      */
79     bool empty() const;
80
81     /**
82      * set the repository checksum \see checksum
83      * \param checksum
84      */
85     RepoStatus & setChecksum( const std::string &checksum );
86
87     /**
88      * set the repository timestamp \see timestamp
89      * \param timestamp
90      */
91     RepoStatus & setTimestamp( const Date &timestamp );
92
93     /** Implementation  */
94     class Impl;
95
96   public:
97     /** Default ctor */
98     RepoStatus();
99
100     /**
101      * \short Status from a single file
102      * As most repository state is represented
103      * by the status of the index file, you can
104      * construct the status from a file.
105      *
106      * \note construct from a non existing
107      * file will result in an empty status
108      */
109     RepoStatus( const Pathname &file );
110
111     /** Dtor */
112     ~RepoStatus();
113
114   public:
115
116   private:
117     /** Pointer to implementation */
118     RWCOW_pointer<Impl> _pimpl;
119   };
120   ///////////////////////////////////////////////////////////////////
121
122   /** \relates RepoStatus Stream output */
123   std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
124
125   /**
126    * combines 2 repostatus with a checksum based on both
127    * checksums and the newest timestamp
128    */
129   RepoStatus operator&&( const RepoStatus &lhs, const RepoStatus &rhs );
130
131   /////////////////////////////////////////////////////////////////
132 } // namespace zypp
133 ///////////////////////////////////////////////////////////////////
134 #endif // ZYPP2_REPOSTATUS_H