libzypp  17.14.0
WatchFile.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_WATCHFILE_H
13 #define ZYPP_BASE_WATCHFILE_H
14 
15 #include <iosfwd>
16 
17 #include "zypp/PathInfo.h"
18 
20 namespace zypp
21 {
22 
24  //
25  // CLASS NAME : WatchFile
26  //
49  class WatchFile
50  {
51  public:
52  enum Initial { NO_INIT, INIT };
53 
54  public:
56  WatchFile( const Pathname & path_r = Pathname(),
57  Initial mode = INIT )
58  : _path( path_r )
59  {
60  PathInfo pi( mode == INIT ? path_r : Pathname() );
61  _size = pi.size();
62  _mtime = pi.mtime();
63  }
64 
65  const Pathname & path() const
66  { return _path; }
67 
68  off_t lastSize() const
69  { return _size;}
70 
71  time_t lastMtime() const
72  { return _mtime; }
73 
74  bool isDirty() const
75  {
76  PathInfo pi( _path );
77  return( _size != pi.size() || _mtime != pi.mtime() );
78  }
79 
80  bool hasChanged()
81  {
82  PathInfo pi( _path );
83  if ( _size != pi.size() || _mtime != pi.mtime() )
84  {
85  _size = pi.size();
86  _mtime = pi.mtime();
87  return true;
88  }
89  return false;
90  }
91 
92  private:
94  off_t _size;
95  time_t _mtime;
96  };
98 
100 } // namespace zypp
102 #endif // ZYPP_BASE_WATCHFILE_H
time_t lastMtime() const
Definition: WatchFile.h:71
bool hasChanged()
Definition: WatchFile.h:80
time_t mtime() const
Definition: PathInfo.h:376
Remember a files attributes to detect content changes.
Definition: WatchFile.h:49
bool isDirty() const
Definition: WatchFile.h:74
off_t lastSize() const
Definition: WatchFile.h:68
time_t _mtime
Definition: WatchFile.h:95
const Pathname & path() const
Definition: WatchFile.h:65
WatchFile(const Pathname &path_r=Pathname(), Initial mode=INIT)
Definition: WatchFile.h:56
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
Pathname _path
Definition: WatchFile.h:93
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1