9eeb24a34ba95c7d467826589fd5bd2459bcf0c3
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

1) /* Blinker
Stefan Schuermans update copyright header

Stefan Schuermans authored 5 years ago

2)    Copyright 2011-2019 Stefan 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)  */
Stefan Schuermans implement common sound dir,...

Stefan Schuermans authored 5 years ago

31) const std::string & File::getPath() const
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

32) {
33)   return m_path;
34) }
35) 
Stefan Schuermans implement common sound dir,...

Stefan Schuermans authored 5 years ago

36) /**
37)  * @brief check if file exists
38)  * @return whether file exists
39)  */
40) bool File::exists() const
41) {
42)   struct stat s;
43)   if (stat(m_path.c_str(), &s)) {
44)     return false; // stat failed -> no such file
45)   }
46)   return true; // stat worked -> file exists
47) }
48) 
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

49) /**
50)  * @brief check if file has been modified
51)  * @return if file has been modified since last check
52)  */
53) bool File::checkModified()
54) {
Stefan Schuermans treating file status change...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

59)   Time modifyTime(s.st_mtime);
60)   Time changeTime(s.st_ctime);
61)   if (changeTime > modifyTime) // treat change same way as modify
62)     modifyTime = changeTime;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

67)   // remember new modify time
68)   m_lastModifyTime = modifyTime;