b6b2996b76e1b0f0e403b4be40430a445bc0873c
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

1) /* Blinker
Stefan Schuermans update copyright years

Stefan Schuermans authored 10 years ago

2)    Copyright 2011-2014Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <string>
7) #include <sys/stat.h>
8) #include <sys/types.h>
9) #include <unistd.h>
10) 
11) #include "File.h"
12) #include "Time.h"
13) 
14) namespace Blinker {
15) 
16) /**
17)  * @brief constructor from path
18)  * @param[in] path path to file
19)  */
20) File::File(const std::string &path):
Stefan Schuermans fix detection of file modif...

Stefan Schuermans authored 13 years ago

21)   m_path(path)
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

22) {
Stefan Schuermans fix detection of file modif...

Stefan Schuermans authored 13 years ago

23)   // get modification time
24)   checkModified();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

25) }
26) 
27) /**
28)  * @brief get path to file
29)  * @return path to file
30)  */
31) const std::string & File::getPath()
32) {
33)   return m_path;
34) }
35) 
36) /**
37)  * @brief check if file has been modified
38)  * @return if file has been modified since last check
39)  */
40) bool File::checkModified()
41) {
Stefan Schuermans treating file status change...

Stefan Schuermans authored 13 years ago

42)   // get modification/change times
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

43)   struct stat s;
44)   if (stat(m_path.c_str(), &s))
45)     return false; // cannot stat -> silently ignore
Stefan Schuermans fix detection of file modif...

Stefan Schuermans authored 13 years ago

46)   Time modifyTime(s.st_mtime);
47)   Time changeTime(s.st_ctime);
48)   if (changeTime > modifyTime) // treat change same way as modify
49)     modifyTime = changeTime;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

50) 
Stefan Schuermans fix detection of file modif...

Stefan Schuermans authored 13 years ago

51)   // consider file modified if modify time changed since last check
52)   bool mod = modifyTime > m_lastModifyTime;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

53) 
Stefan Schuermans fix detection of file modif...

Stefan Schuermans authored 13 years ago

54)   // remember new modify time
55)   m_lastModifyTime = modifyTime;