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