Stefan Schuermans commited on 2011-10-24 21:29:34
              Showing 2 changed files, with 12 additions and 13 deletions.
            
| ... | ... | @@ -18,9 +18,10 @@ namespace Blinker { | 
| 18 | 18 | * @param[in] path path to file | 
| 19 | 19 | */ | 
| 20 | 20 | File::File(const std::string &path): | 
| 21 | - m_path(path), | |
| 22 | - m_lastCheck(Time::now()) | |
| 21 | + m_path(path) | |
| 23 | 22 |  { | 
| 23 | + // get modification time | |
| 24 | + checkModified(); | |
| 24 | 25 | } | 
| 25 | 26 |  | 
| 26 | 27 | /** | 
| ... | ... | @@ -38,22 +39,20 @@ const std::string & File::getPath() | 
| 38 | 39 | */ | 
| 39 | 40 | bool File::checkModified() | 
| 40 | 41 |  { | 
| 41 | - /* get current time before getting modification time | |
| 42 | - for not missing any modification */ | |
| 43 | - Time now = Time::now(); | |
| 44 | - | |
| 45 | 42 | // get modification/change times | 
| 46 | 43 | struct stat s; | 
| 47 | 44 | if (stat(m_path.c_str(), &s)) | 
| 48 | 45 | return false; // cannot stat -> silently ignore | 
| 49 | - Time modified(s.st_mtime); | |
| 50 | - Time changed(s.st_ctime); | |
| 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; | |
| 51 | 50 |  | 
| 52 | - // has file been modified/changed since last check | |
| 53 | - bool mod = modified >= m_lastCheck || changed >= m_lastCheck; | |
| 51 | + // consider file modified if modify time changed since last check | |
| 52 | + bool mod = modifyTime > m_lastModifyTime; | |
| 54 | 53 |  | 
| 55 | - // remember "now" as last check time | |
| 56 | - m_lastCheck = now; | |
| 54 | + // remember new modify time | |
| 55 | + m_lastModifyTime = modifyTime; | |
| 57 | 56 |  | 
| 58 | 57 | return mod; | 
| 59 | 58 | } | 
| ... | ... | @@ -37,7 +37,7 @@ public: | 
| 37 | 37 |  | 
| 38 | 38 | protected: | 
| 39 | 39 | std::string m_path; ///< path to file | 
| 40 | - Time m_lastCheck; ///< last time modification time was checked | |
| 40 | + Time m_lastModifyTime; ///< last known modification time was checked | |
| 41 | 41 | }; // class File | 
| 42 | 42 |  | 
| 43 | 43 | } // namespace Blinker | 
| 44 | 44 |