libzypp: zypp-core/fs/watchfile.h Source File

libzypp 17.38.6

watchfile.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CORE_FS_WATCHFILE_H
13#define ZYPP_CORE_FS_WATCHFILE_H
14
15#include <iosfwd>
16
17#include <zypp-core/fs/PathInfo.h>
18
20namespace 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 { ctorInit( mode ); }
60
61 WatchFile( Pathname && path_r, Initial mode = INIT )
62 : _path( std::move(path_r) )
63 { ctorInit( mode ); }
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:
93 void ctorInit( Initial mode )
94 {
95 PathInfo pi( mode == INIT ? _path : Pathname() );
96 _size = pi.size();
97 _mtime = pi.mtime();
98 }
99
100 private:
101 Pathname _path;
102 off_t _size;
103 time_t _mtime;
104 };
105
106
108} // namespace zypp
110#endif // ZYPP_CORE_FS_WATCHFILE_H
zypp::WatchFile::WatchFile
WatchFile(const Pathname &path_r=Pathname(), Initial mode=INIT)
Definition watchfile.h:56
zypp::WatchFile::_mtime
time_t _mtime
Definition watchfile.h:103
zypp::WatchFile::hasChanged
bool hasChanged()
Definition watchfile.h:80
zypp::WatchFile::ctorInit
void ctorInit(Initial mode)
Definition watchfile.h:93
zypp::WatchFile::isDirty
bool isDirty() const
Definition watchfile.h:74
zypp::WatchFile::lastSize
off_t lastSize() const
Definition watchfile.h:68
zypp::WatchFile::path
const Pathname & path() const
Definition watchfile.h:65
zypp::WatchFile::_size
off_t _size
Definition watchfile.h:102
zypp::WatchFile::Initial
Initial
Definition watchfile.h:52
zypp::WatchFile::NO_INIT
@ NO_INIT
Definition watchfile.h:52
zypp::WatchFile::INIT
@ INIT
Definition watchfile.h:52
zypp::WatchFile::_path
Pathname _path
Definition watchfile.h:101
zypp::WatchFile::WatchFile
WatchFile(Pathname &&path_r, Initial mode=INIT)
Definition watchfile.h:61
zypp::WatchFile::lastMtime
time_t lastMtime() const
Definition watchfile.h:71
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::PathInfo::mtime
time_t mtime() const
Definition PathInfo.h:384
zypp::filesystem::PathInfo::size
off_t size() const
Definition PathInfo.h:376
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
std
Definition ansi.h:855
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
PathInfo.h