WatchFile.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_BASE_WATCHFILE_H
00013 #define ZYPP_BASE_WATCHFILE_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/PathInfo.h"
00018 
00020 namespace zypp
00021 { 
00022 
00024   //
00025   //    CLASS NAME : WatchFile
00026   //
00049   class WatchFile
00050   {
00051     public:
00052       enum Initial { NO_INIT, INIT };
00053 
00054     public:
00056       WatchFile( const Pathname & path_r = Pathname(),
00057                  Initial mode            = INIT )
00058       : _path( path_r )
00059       {
00060         PathInfo pi( mode == INIT ? path_r : Pathname() );
00061         _size  = pi.size();
00062         _mtime = pi.mtime();
00063       }
00064 
00065       const Pathname & path() const
00066       { return _path; }
00067 
00068       bool hasChanged()
00069       {
00070         PathInfo pi( _path );
00071         if ( _size != pi.size() || _mtime != pi.mtime() )
00072         {
00073           _size = pi.size();
00074           _mtime = pi.mtime();
00075           return true;
00076         }
00077         return false;
00078       }
00079 
00080     private:
00081       Pathname _path;
00082       off_t  _size;
00083       time_t _mtime;
00084   };
00086 
00088 } // namespace zypp
00090 #endif // ZYPP_BASE_WATCHFILE_H

doxygen