Imported Upstream version 17.14.0
[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     /** Dtor */
56     ~RepoStatus();
57
58   public:
59     /** Reads the status from a cookie file
60      * \returns An empty \ref RepoStatus if the file does not
61      * exist or is not readable.
62      * \see \ref saveToCookieFile
63      */
64     static RepoStatus fromCookieFile( const Pathname & path );
65
66     /** Save the status information to a cookie file
67      * \throws Exception if the file can't be saved
68      * \see \ref fromCookieFile
69      */
70     void saveToCookieFile( const Pathname & path_r ) const;
71
72   public:
73     /** Whether the status is empty (default constucted) */
74     bool empty() const;
75
76     /** The time the data were changed the last time */
77     Date timestamp() const;
78
79   public:
80     struct Impl;                        ///< Implementation
81   private:
82     RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation
83   };
84   ///////////////////////////////////////////////////////////////////
85
86   /** \relates RepoStatus Stream output */
87   std::ostream & operator<<( std::ostream & str, const RepoStatus & obj );
88
89   /** \relates RepoStatus Combine two RepoStatus (combined checksum and newest timestamp) */
90   RepoStatus operator&&( const RepoStatus & lhs, const RepoStatus & rhs );
91
92   /** \relates RepoStatus Whether 2 RepoStatus refer to the same content checksum */
93   bool operator==( const RepoStatus & lhs, const RepoStatus & rhs );
94
95   /** \relates RepoStatus Whether 2 RepoStatus refer to different content checksums */
96   inline bool operator!=( const RepoStatus & lhs, const RepoStatus & rhs )
97   { return ! ( lhs == rhs ); }
98
99   /////////////////////////////////////////////////////////////////
100 } // namespace zypp
101 ///////////////////////////////////////////////////////////////////
102 #endif // ZYPP2_REPOSTATUS_H