1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/WatchFile.h
12 #ifndef ZYPP_BASE_WATCHFILE_H
13 #define ZYPP_BASE_WATCHFILE_H
17 #include "zypp/PathInfo.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
25 // CLASS NAME : WatchFile
27 /** Remember a files attributes to detect content changes.
29 * Repeatedly call \ref hasChanged to check whether the content has
30 * changed since the last call. Creation or deletion of the file will
31 * be reported as change as well.
33 * Per default the ctor stats the file, so \ref hasChanged will detect
34 * changes done after \ref WatchFile was created.
36 * You may omit the initial stat by passing \c NO_INIT as second argument
37 * to the ctor. \ref WatchFile will behave as if the file did not exist
38 * at the time \ref WatchFile was created.
41 * static WatchFile sysconfigFile( "/etc/sysconfig/SuSEfirewall2",
42 * WatchFile::NO_INIT );
43 * if ( sysconfigFile.hasChanged() )
45 * // reload the file...
52 enum Initial { NO_INIT, INIT };
56 WatchFile( const Pathname & path_r = Pathname(),
60 PathInfo pi( mode == INIT ? path_r : Pathname() );
65 const Pathname & path() const
68 off_t lastSize() const
71 time_t lastMtime() const
77 return( _size != pi.size() || _mtime != pi.mtime() );
83 if ( _size != pi.size() || _mtime != pi.mtime() )
97 ///////////////////////////////////////////////////////////////////
99 /////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////
102 #endif // ZYPP_BASE_WATCHFILE_H