184a36587c4d8c1d7ddc6e7edf59833992042369
[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   /// \class RepoStatus
26   /// \brief Track changing files or directories.
27   ///
28   /// Compute timestamp and checksum for individual files or
29   /// directories (recursively) to track changing content.
30   ///
31   /// The timestamp most probably denotes the time the data were
32   /// changed the last time, that's why it is exposed.
33   ///
34   /// The checksum however is an implementation detail and of no
35   /// use outside this class. \ref operator== tells if the checksums
36   /// of two rRepoStatus are the same.
37   ///////////////////////////////////////////////////////////////////
38   class RepoStatus
39   {
40     friend std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
41     friend RepoStatus operator&&( const RepoStatus & lhs, const RepoStatus & rhs );
42     friend bool operator==( const RepoStatus & lhs, const RepoStatus & rhs );
43
44   public:
45     /** Default ctor */
46     RepoStatus();
47
48     /** Compute status for single file or directory (recursively)
49      *
50      * \note Construction from a non existing file will result
51      * in an empty status.
52      */
53     explicit RepoStatus( const Pathname & path_r );
54
55     /** Explicitly specify checksum string and timestamp to use. */
56     RepoStatus( std::string checksum_r, Date timestamp_r );
57
58     /** Dtor */
59     ~RepoStatus();
60
61   public:
62     /** Reads the status from a cookie file
63      * \returns An empty \ref RepoStatus if the file does not
64      * exist or is not readable.
65      * \see \ref saveToCookieFile
66      */
67     static RepoStatus fromCookieFile( const Pathname & path );
68
69     /** Save the status information to a cookie file
70      * \throws Exception if the file can't be saved
71      * \see \ref fromCookieFile
72      */
73     void saveToCookieFile( const Pathname & path_r ) const;
74
75   public:
76     /** Whether the status is empty (default constucted) */
77     bool empty() const;
78
79     /** The time the data were changed the last time */
80     Date timestamp() const;
81
82   public:
83     struct Impl;                        ///< Implementation
84   private:
85     RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation
86   };
87   ///////////////////////////////////////////////////////////////////
88
89   /** \relates RepoStatus Stream output */
90   std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
91
92   /** \relates RepoStatus Combine two RepoStatus (combined checksum and newest timestamp) */
93   RepoStatus operator&&( const RepoStatus & lhs, const RepoStatus & rhs );
94
95   /** \relates RepoStatus Whether 2 RepoStatus refer to the same content checksum */
96   bool operator==( const RepoStatus & lhs, const RepoStatus & rhs );
97
98   /** \relates RepoStatus Whether 2 RepoStatus refer to different content checksums */
99   inline bool operator!=( const RepoStatus & lhs, const RepoStatus & rhs )
100   { return ! ( lhs == rhs ); }
101
102   /////////////////////////////////////////////////////////////////
103 } // namespace zypp
104 ///////////////////////////////////////////////////////////////////
105 #endif // ZYPP2_REPOSTATUS_H